I have a struct that is declared outside main() for the purpose of being accessible by other functions. However, I can't access it from all functions for some reason. Here's the relevant part of the code:
Code:
struct FILELIST{
char filename[255];
};
struct FILELIST *filelist;
void load_file_list(char *filename, FILELIST *filelist){ //this function works as expected
FILE *handle;
char filename_new[255];
unsigned long n=0;
filelist = (FILELIST*)malloc(sizeof(FILELIST)); //allocate mem for first filename
while(1){
sprintf(filename_new,"%s%06lu.jpg",filename,n);
if(handle = fopen(filename_new, "rb")){
fclose(handle);
filelist = ((FILELIST*)realloc(filelist, sizeof(FILELIST)*(n+1))); //add more memory
strcpy(filelist[n].filename,filename_new); //copy new filename to struct
printf("Filename is %s\n",filelist[n].filename); //this works OK
}else{
printf("No more files\n");
break;
}
n++;
}
}
void print_filename(void){ //this doesn't work
printf("Filename: %s\n",filelist[0].filename);
}