In creating a program to read an inventory list, ran into a segmentation fault, I tried removing lines in the program using // and still couldn't find the problem, Im pretty sure the problem is with the pointer not the NULL due to the testing iv done but not completely sure.
Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int item, volume, quantity;
char description[50], author[30];
int ISBN;
}rectype;
int main()
{
rectype rec;
FILE *f;
//initialize
if ((f = fopen("GRANDVENTORY", "r")) == NULL)
{
printf("\n\n\n\n\n\t\t\tAWWWW FUUUUIII....Unable to open file GRANDVENTORY!!!\n\n\n\n\n");
return(1);
}
do
{
fscanf(f, "%d", rec.item);
if (!feof(f))
{
fscanf(f, "%s", rec.description);
fscanf(f, "%d", rec.volume);
fscanf(f, "%d", rec.quantity);
fscanf(f, "%s", rec.author);
fscanf(f, "%d", rec.ISBN);
printf(" %d \t\t %d \t\t %s \t\t %s \t\t %d \t\t %d \n", rec.item, rec.ISBN, rec.description, rec.author, rec.volume, rec.quantity);
}
}while(!feof(f));
fclose(f);
return(0);
}