In an SO answer I wrote this code:
char fail_on_eof (int c)
{
if (c == EOF)
exit (EXIT_FAILURE);
return (char) c;
}
void skip_to_next_line (void)
{
char c;
do
{
c = fail_on_eof (getchar ());
} while (c != '\n');
}
I was wondering whether there are any terminals that may return '\r'
(which is covered by the above code as long as there is also a '\n'
at end of line).
Does stdin
ever contain '\r'
(on any platform)? What about input redirection is stdin
always working in text mode?