I have some code and I keep getting segfaults, I have found out here the error is happening and it happens when I am trying to assign values to a structure. I thought I had done it right but apparently not. Here is my code and I put comments were the error is happening in the fillStruct function.
Code:
#include <stdio.h>
#include <stdbool.h>
struct NODE //list node
{
char destination;
struct NODE* next;
};
struct LIST //linked list
{
char startingPoint;
struct NODE* first;
};
void fillStruct(char* fileName, struct LIST map[]);
void printList(struct LIST map[]);
void depthSearch(struct LIST map[]);
void breadth(struct LIST map[]);
void topoSort(struct LIST map[]);
struct NODE* ListIterator(struct NODE* start);
void fillStruct(char* fileName, struct LIST map[]){
char points[60];
FILE* fpIn;
int i=0;
char readIn=' ';
int j=0;
struct NODE* temp;
for(j=0;j<60;j++)
points[j]=' ';
if((fpIn=fopen(fileName,"r"))!=NULL)
do{
readIn=getc(fpIn);
if(readIn!=EOF && readIn>='A')
points[i++]=readIn;
}while(readIn<'A' && readIn!=EOF);
for(j=0;points[j]!=' ';j+=2){
if(map[(int)points[j]-65].startingPoint==' ')
map[(int)points[j]-65].startingPoint=points[j];
temp->destination=points[j+1]; //error happens here
temp->next=NULL; // and here
if(map[(int)points[j]-65].first==NULL)
map[(int)points[j]-65].first=temp;
else{
ListIterator(map[(int)points[j]-65].first)->next=temp;
}
}//end for loop
}
any help is greatly appreciated, Thanks.