x
This website is using cookies. We use cookies to ensure that we give you the best experience on our website. More info. That's Fine
HPC:Factor Logo 
 
Latest Forum Activity

System Error When Using scanf

[Frozen]
Frozen
nathanpc Page Icon Posted 2009-09-09 5:54 AM
#
Avatar image of nathanpc
H/PC Philosopher

Posts:
327
Location:
Portugal
Status:
Hello,
I'm learning C(But i already know C++ and developing some simple applications just to learn better, but when i try to execute my application on my Jornada 720 i got an error, see the attachement. And here is my code:
// Remove.cpp : Defines the entry point for the application. 
 
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>

bool Delete(LPCWSTR File); // Prototype

int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow )
{
LPCWSTR sFile;
printf("Enter The File To Delete: ";
scanf("%s", sFile);
Delete(sFile); // Filename to delete
return 0;
}

bool Delete(LPCWSTR File)
{
DeleteFile(File);
return DeleteFile;
}

What is Wrong?

Thanks,
Nathan Paulino Campos



(CAPT0000.JPG)



Attachments
----------------
Attachments CAPT0000.JPG (27KB - 5 downloads)
 Top of the page
mscdex Page Icon Posted 2009-09-09 1:27 PM
#
Avatar image of mscdex
H/PC Sensei

Posts:
1,054
Location:
United States
Status:
Well, exception 0xc0000005 indicates a memory access violation.

I've never really developed Windows software in pure C++ using Windows API structs/datatypes/etc, but an alternative could be to read in a char* string (named charpath in the example below) from the console instead and then do:
TCHAR path[MAX_PATH+1];
MultiByteToWideChar(CP_ACP, 0, charpath, -1, path, MAX_PATH);
DeleteFile(path);

I haven't tested it though.
 Top of the page
nathanpc Page Icon Posted 2009-09-09 1:29 PM
#
Avatar image of nathanpc
H/PC Philosopher

Posts:
327
Location:
Portugal
Status:
Huh , thanks very much mscdex!
All is working now!
 Top of the page
Frozen
Jump to forum:
Seconds to generate: 0.141 - Cached queries : 59 - Executed queries : 11