hey, im having a problem getting file stored into linkedlists. the program crushes when start reading.
these are the structs:
typedef struct category
{
char categoryID[5];
char categoryName[25];
char fareType;
char categoryDescription[250];
unsigned numItems;
ItemTypePtr headItem; //ptr to item struct
CategoryTypePtr nextCategory;
} CategoryType;
typedef struct item
{
char itemID[5];
char itemName[25];
char itemDescription[250];
ItemTypePtr nextItem;
} ItemType;
typedef struct fms
{
CategoryTypePtr headCategory;
unsigned numCategories;
} FMSType;
the format of the file is like:
F0001|F|Daily|Allow unlimited train, tram and bus travel for a whole day within selected zones.
F0002|F|3 hour|Allow unlimited train, tram and bus travel for at least two hours within selected zones.
F0003|F|10 hour|Allow ten 2 hour trips in a single ticket at a discounted price, but can only be used by one person at a time.
each field splited by |.
code:
int loadData( FMSType* fms, char* fareFile, char* subfareFile)
{
int data = 0;
FILE *fp1, *fp2;
if((fp1 = fopen(fareFile, "r"))==NULL && ((fp2 = fopen(subfareFile, "r"))==NULL)) {
printf("Cannot open file.\n");
return data = 1;
exit(1);
}
fscanf(fp1, "%s%s%s%s", fms->headCategory->categoryID, &fms->headCategory->fareType,&fms->headCategory->categoryName, &fms->headCategory->categoryDescription);
/*fscanf(fp2, "%s%s%s%s",fms->headCategory->headItem->itemID, fms->headCategory->categoryID, fms->headCategory->headItem->itemName, fms->headCategory->headItem->itemDescription);
fclose(fp1);
fclose(fp2);
return data = 1;
}
how can i get these stored into linkedlists. any help is much appreciated.