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