I'm pretty new to C programming and I am trying to build a console application that takes in some user survey data into a singly linked list and generates statistics out of it.
The main idea is that every time application user opens up the application, the existing survey data is loaded from text file into linked list nodes. User can then manipulate data as they want.
My issue is that application crashes every time the importList function is called and I can't figure out where my issue is. I would be really grateful if anyone can point out where my mistake is. Thank you.
Here is the function for importing data from text file:
void importList(struct nodeList** head)
{
//set up the linked list node by node
struct nodeList *temp;
temp =(struct nodeList*)malloc(sizeof(struct nodeList));
temp = *head;
//open survey data file in read mode to import existing survey data
openSurveyFile();
//read in data that's in the text file to nodes in linked list
while(!feof(surFPtr))
{
//import data from file. All data except address is held in single word lines.
fscanf(surFPtr, "%d", &temp->PPS);
fscanf(surFPtr, "%s", temp->name);
fscanf(surFPtr, "%s", temp->surname);
fgets(temp->address, 50, surFPtr);//since address is a multiword string the list needs to read the entire line
fscanf(surFPtr, "%s", temp->eMail);
fscanf(surFPtr, "%d", &temp->age);
fscanf(surFPtr, "%d", &temp->income);
fscanf(surFPtr, "%s", temp->gender);
fscanf(surFPtr, "%d", &temp->exercise);
fscanf(surFPtr, "%d", &temp->alcohol);
fscanf(surFPtr, "%d", &temp->smoking);
fflush(stdin);
//allocate memory for the next node in list
temp->next =(struct nodeList*)malloc(sizeof(struct nodeList));
temp = temp->next;//move on to next node
}
//close survey data file once all data is imported
closeSurveyFile();
}//end of importList function