Hello,
I have a small program which uses FindFirstFile() to get a file name. Once I get the file name, I would like to use sscanf to extract certain part of the file name.
My program is as follows :
......
int _tmain(int argc, _TCHAR* argv[])
{
WIN32_FIND_DATA ffd;
TCHAR szDir[MAX_PATH];
HANDLE hFind = INVALID_HANDLE_ VALUE;
DWORD dwError = 0;
char filename[128];
char ext[128];
StringCchCopy (szDir, MAX_PATH, TEXT(".\\*.dat" ));
hFind = FindFirstFile (szDir, &ffd);
if (hFind == INVALID_HANDLE_ VALUE)
{
dwError = GetLastError();
if (dwError == ERROR_PATH_NOT_ FOUND)
_tprintf (TEXT("[Error] Directory not found\n");
else
_tprintf (TEXT("FindFirs tFile failed (%u)\n", dwError);
return dwError;
}
else
{
_tprintf(TEXT ("File name : %s\n"), ffd.cFileName);
if (sscanf_s (ffd.cFileName, "%16s.%3s", filename, ext) == 2)
{
printf("File Name : %s\n", filename);
printf("Extensi on : %s\n", ext);
}
else
printf ("sscanf_s failed\n");
}
}
And I got a compile-time error message saying "error C2664 : 'sscanf_s' cannot convert parameter 1 from 'WCHAR [260]' to 'const char *' Types pointed to are unrelated; conversion requires reinterpret_cas t, C-stype cast or function-style cast.
Could anyone please help me fix this compile-time error?
Thank you very much for your help.
Akino
I have a small program which uses FindFirstFile() to get a file name. Once I get the file name, I would like to use sscanf to extract certain part of the file name.
My program is as follows :
......
int _tmain(int argc, _TCHAR* argv[])
{
WIN32_FIND_DATA ffd;
TCHAR szDir[MAX_PATH];
HANDLE hFind = INVALID_HANDLE_ VALUE;
DWORD dwError = 0;
char filename[128];
char ext[128];
StringCchCopy (szDir, MAX_PATH, TEXT(".\\*.dat" ));
hFind = FindFirstFile (szDir, &ffd);
if (hFind == INVALID_HANDLE_ VALUE)
{
dwError = GetLastError();
if (dwError == ERROR_PATH_NOT_ FOUND)
_tprintf (TEXT("[Error] Directory not found\n");
else
_tprintf (TEXT("FindFirs tFile failed (%u)\n", dwError);
return dwError;
}
else
{
_tprintf(TEXT ("File name : %s\n"), ffd.cFileName);
if (sscanf_s (ffd.cFileName, "%16s.%3s", filename, ext) == 2)
{
printf("File Name : %s\n", filename);
printf("Extensi on : %s\n", ext);
}
else
printf ("sscanf_s failed\n");
}
}
And I got a compile-time error message saying "error C2664 : 'sscanf_s' cannot convert parameter 1 from 'WCHAR [260]' to 'const char *' Types pointed to are unrelated; conversion requires reinterpret_cas t, C-stype cast or function-style cast.
Could anyone please help me fix this compile-time error?
Thank you very much for your help.
Akino
Comment