Search code examples
cfgets

How to read beyond new line characters using fgets() function?


I understand from C manpage that using fgets(), reading stops after an EOF or a newline. i have a program that reads from file(with multiple lines) and reading stop at the end of new line.

Is there a way to forcefgets() to ignore newlines and read till EOF?

while(fgets(str,1000, file))
{ 
 // i do stuffs with str here
}

Solution

  • Is there a way to force fgets() to ignore newlines and read till EOF?

    No, you can't because fgets() is implemented in such a way that the parsing will stops if end-of-file occurs or a newline character is found. May you can consider using other file i/o function like fread().