Well, I'm not able to make it work on my real code... This is the code I have:
Code:
void loadCategories(void) {
struct dirent *dpItem;
char **catList;
int i, j;
DIR *dp;
if((dp = opendir("data/games/JF")) != NULL) {
while((dpItem = readdir(dp)) != NULL) {
if(strcmp(dpItem->d_name, ".") && strcmp(dpItem->d_name, "..")) {
catList[i] = malloc((strlen(dpItem->d_name) + 1) * sizeof(char));
strcpy(catList[i++], dpItem->d_name);
}
}
mvprintw(0,0, "%s\n", catList[0]);
/*for (j = 0; j < i; i++) {
printw("%s\n", catList[j]);
}*/
refresh();
closedir(dp);
}
}
The problem is on the line mvprintw(0,0, "%s\n", catList[0]); which produces a segmentation fault, the code works if I comment that line (as you can see with the below for loop commented, cause I was trying to print all files found). But that won't help cause I need to print the file names found...
Just in case you don't know (which I doubt) the printw() is cause I'm using ncurses and it works in the same way as printf().
What's wrong with my code?