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) {
do{
strcpy(sListing[i], win32FindData.cFileName);
i++;
}while (FindNextFile(hFile, &win32FindData)) ;
FindClose(hFile);
}
(*iLength) = i;
return 0;
}
A do...while can shorten your code
The error
char[][] is very diferent from char ** !!!!
char [][] is an array of char[] which is stored sequentialy in memory
This this
Code:
char a[2][2]={{'a','b'},{'c',0}};
puts((char*)a);
char* is an array of pointers to char. Each pointer holds a memory adress to wherelse in your heap, so you can't cast your var like that
Code:
char *a[2][2]={"abc","def"};
printf("the adresses %x %x\n",a[0],a[1])
puts(a[0]);puts(a[1]);
possibles fixes:
change the function prototipe
Code:
DWORD DirListing
(
char* sDir,
char sListing[][MAX_FILENAME],
int* iLength
)
/***
redeclare your double array, and alocate memory
Code:
char *sFiles[MAX_NUMBER_OF_FILES];
for(i=0;i<MAX_NUMBER_OF_FILES;i++){
sFiles[i]=calloc(MAX_FILENAME,1);
}
or use static memory,
Code:
char sFilesBuffer[MAX_NUMBER_OF_FILES][MAX_FILENAME];
char *sFiles[MAX_NUMBER_OF_FILES];
for(i=0;i<MAX_NUMBER_OF_FILES;i++){
sFiles[i]=sFilesBuffer[i];
}