My other functions work fine but once I call this readfile funtions, I have an exit code/core dump. Temp is pointer pointing to a double pointer (the linked list itself). I have a feeling the error is somewhere in the first 6 lines because I am positive everything else is correct.
I have tried to change around my strategy in of the temp->next and how I move the pointer throughout the list but nothing seems to work
while ( !feof(fp) && return_val == 0 ){
if ( temp != NULL ){
temp = malloc(sizeof(struct record));
temp->next = next;
next->next = NULL;
temp = temp->next;
}
fscanf(fp, "%*s %*s %d",&temp->accountno);
track = 0;
while ( track == 0 ){
ch = fgetc(fp);
if ( ch == '<'){
ch = fgetc(fp);
while ( ch != '>' ){
temp->name[ni] = ch;
ch = fgetc(fp);
ni++;
}
temp->name[ni] = '\0';
} else if ( ch == '['){
ch = fgetc(fp);
while ( ch != ']' ){
temp->address[ai] = ch;
ch = fgetc(fp);
ai++;
}
temp->address[ai] = '\0';
track = 1;
}
}
ni = 0;
ai = 0;
}
I expect the program to simply read the file, the function takes in a double pointer and a string array(name of the file) and it is supposed to read from the file, the account number, name, and address and store it in the linked list.