For some reason, I am getting a segmentation fault when I try to run this test code. The program is supposed to read strings from a file and put them into an array. I'm new to C and have tried using a debugger but I am having trouble with it.
Any input would be greatly appreciated.
void fillArray(char *array[], int * count, FILE * fpin){
char buf[40];
char *p;
count = 0;
while(fgets(buf, 40, fpin) != NULL){
if((p= strchr(buf, '\n')) != NULL)
*p = '\0'; //step on the '\n'
array[(*count)++] = malloc(strlen(buf)+1);
assert(array[*count]);
strcpy(array[*count], buf);
(*count)++;
}
}
count = 0that should be*count = 0, that is?]*counttwice.fillArrayfunction? I.e. where and how you getarrayand other parameters?