Does fgets() always terminate the char buffer with \\0 even if EOF is already reached? It looks like it does (it certainly does in the implementation presented in the ANSI K&
fgets
does always add a '\0' to the read buffer, it reads at most size - 1
characters from the stream (size
being the second parameter) because of this.
Never use gets
as you can never guarantee that it won't overflow any buffer that you give it, so while it technically does always terminate the read string this doesn't actually help.