I want to read a fixed length of chars from a file. Therefore I use fgets, but fgets stops at "\n" reading.
How can I read the first N char even though one of them is a newline character?
I tried searching for other functions in the documentation but found none.
To read a fixed number of bytes from a stream, you should use
fread:freadattempts to readnmembelements ofsizebytes each and returns the number of elements successfully read. It returns0at end of file.Also make sure the file is opened in binary more with
"rb"to prevent the translation of line ending sequences on legacy systems that may interfere with the byte counts.