my c program will only read the first line of my file

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);


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.

Leave a Comment

Your email address will not be published.

Scroll to Top