C: unable to print from file

In your:

if ( buff == '\n' && fe && fn )        //<--

I assume you want to check if an empty line was read by checking it against the newline character. However, buff is not the character; it is a pointer to were all the characters read are stored. To check if the first character of buff is the newline character, use:

if ( *buff == '\n' && fe && fn )        //<--

The * dereferences the pointer and gives you the first character. Same for your other checks. If these checks fail, then print the line:

else
    printf("%s", buff);

Note the formatting character %s, not %c, to print a string (the buffer) instead of a single character.

Leave a Comment