Your code is overly complicated and wrong.
You probably want this:
void readInBooks(Catalog *cat, char const *filename)
{
FILE *fp = fopen(filename, "r");
if (!fp)
{
fprintf(stderr, "Can't open file: %s\n", filename);
exit( BAD_INPUT );
}
char *line;
while ((line = readline(fp)) != NULL)
{
printf("Line: %s", line);
}
fclose(fp);
}
There maybe more problems elsewhere though.
There are also some problems in readline
, I let you find out what as an exercise. Hint: it leaks memory.
CLICK HERE to find out more related problems solutions.