Let's say i have a file containing a string of length 10 :
abcdefghij
And read my text file line by line using fgets()
with a buffer of size 4.
I will have to call fgets()
in a loop to make sure the whole line is read.
But, at say the first call, it will read the first 3 characters (buffer size -1)
right ? Will it also append a null terminating character at the last position of my 4 char buffer even if the real end of my string wasn't reached, or will fill it with 4 characters and no null terminating characters at the end of my buffer ? which would make a call to strlen()
impossible ?
Thank you :)
Looking at the man page of fgets you can see :
"The newline, if any, is retained. If any characters are read and there is no error, a `\0' character is appended to end the string"
(http://www.manpagez.com/man/3/fgets/)
It is in the documentation.
Verbatim from
man fgets
(italics by me):Verbatim from the HP-UX 11 man page (italics by me):
From the POSIX specs:
Last not least from MSDN:
From C standard draft (2010) n1547.pdf, 7.21.7.2.2: