Segmentation fault (core dumped)
In C, I initialized an array of strings, like this:
char* strings[20];
then tried to fscanf a bunch of stuff.
for(int i = 0; i<20; i++){
fscanf(file, "%s", strings[i]);
}
although there is more to the program, I am sure that this is the part causing a segmentation fault. A run using gdb stated that the error was in file vfscanf, so I think this is related.
malloc(sizeof(char)*20)inside theforloop for each string, but it did not work. I also triedchar* strings[20] = {"","","",""...};to no avail.strings[i]=malloc(sizeof(char)*20)inside theforloop? Are you sure that all 20 strings read are no more than 19 characters (keeping in mind that you need 1 char for the null-terminating character)?