I have declared the following variable in a fuction:
Code:
char sFiles[MAX_NUMBER_OF_FILES][MAX_FILENAME];
Then I have a function that retrieves the file listing of a given directory:
Code:
/****************************************************************************/
DWORD DirListing
(
char* sDir,
char** sListing,
int* iLength
)
/****************************************************************************/
{
WIN32_FIND_DATA win32FindData;
HANDLE hFile;
char sDirListOfTxt[MAX_PATH];
int i;
sprintf(sDirListOfTxt, "%s\\*.jar", sDir);
i = 0;
hFile = FindFirstFile(sDirListOfTxt, &win32FindData);
if (hFile!=INVALID_HANDLE_VALUE) {
strcpy(sListing[i], win32FindData.cFileName);
i++;
while (FindNextFile(hFile, &win32FindData)) {
strcpy(sListing[i], win32FindData.cFileName);
i++;
}
FindClose(hFile);
}
(*iLength) = i;
return 0;
}
When I call this function I do:
Code:
DirListing(sDir, (char**)sFiles, &iFilesLength);
But everytime I execute the program, it just exited before it even begans with a Windows error that doesn't tell anything about it.
I guess it's a matter of pointers, but now I can't see where is the error. Any help?
And another more question... If I don't want to declare sFiles that way, and I just want to make it char**, how can I allocate memory in order to store an array of strings.
Thanks in advance.