Based on your edit, the input line ends in \r\n
. As a workaround you could just add \r
to your list of tokens in strtok.
However, this should be investigated further. \r\n
is the line ending in a Windows file, but stdin
is a text stream, so \r\n
in a file would be converted to just \n
in the fgets
result.
Are you perhaps piping in a file that contains something weird like \r\r\n
? Try hex-dumping the file you're piping in to check this.
Another possible explanation might be that your Cygwin (or whatever) environment has somehow been configured not to translate line endings in a file piped in.
edit: Joachim's suggestion is much more likely - using a \r\n
file on a non-Windows system. If this is the case , you can fix it by running dos2unix
on the file. But in accordance with the principle "accept everything, generate correctly" it would be useful for your program to handle this file.