fgets()
reads one character less than the given buffer size from stdin and then
appends a NUL-character. So in your case, with an input buffer of 6 characters,
it reads "asd d" into arcInputString5
, and the newline character that terminates the line input is still unread.
The next fgets()
then reads (only) this newline character into arcInputString10
.
You need a buffer size of (at least) 7 to read the five characters "asd d" including the newline character from stdin.
The same applies to your other buffers used for fgets()
.
Added: As Jonathan Leffler correctly commented, a better method is to supply
a "large" input buffer to fgets()
and check the actual length of the user input after
reading one line.
You should also note that fgets()
returns NULL if no character could be read at all
(end-of-file), so you should check the return value.