fgets writes nul terminator to the buffer you specify (if you specify a buffer size greater than 0). Otherwise, you could not call strlen () on it, strlen () expects a string, and if it is not nul completed, it is not a string.
You ask about
line[ strlen( line ) - 1 ] = '\0';
line. , , a\n nul-.
, fgets , . line "Hello\n" (\n - escape- , 1 , 2)
strlen ( "Hello\n" ) 6, 6-1 - 5, 5. 0
"Hello\n"
^
|
Add 0 terminator
:
""
:
- [strlen () - 1] = '\ 0'; , [-1].
- , fgets.
line, fgets , . - , , . , , ,
kMaxLineLength , , "" \n, strlen () -1 \n ( ).