E
Eric Sosman
Nikos Chantziaras wrote On 08/01/07 11:03,:
It's certainly not possible in portable C, and I don't
see how it could be possible at all:
int will_get_eof = _eof(_fileno(stdin));
int got_eof;
printf ("Carnac the Magnificent predicts "
"that you %s about to press ^Z\n",
will_get_eof ? "are" : "are not");
(void)getchar();
got_eof = feof(stdin);
if ( (got_eof == 0) == (will_get_eof == 0) )
printf ("Carnac was right, as always.\n");
else
printf ("May the fleas of a thousand camels "
"take refuge in your shorts.\n");
I formulated it a bit "weird". It's porting work, btw, (from win32 to
"as portable as possible") so not everything is 100% clear to even me,
since I'm not the implementor of the original; I just do the porting
In any event, the original is "_eof(_fileno(stdin))" which checks for
EOF on stdin without blocking. In other words, it allows for knowing
beforehand if EOF would be returned when attempting to read from stdin
without actually reading.
It's certainly not possible in portable C, and I don't
see how it could be possible at all:
int will_get_eof = _eof(_fileno(stdin));
int got_eof;
printf ("Carnac the Magnificent predicts "
"that you %s about to press ^Z\n",
will_get_eof ? "are" : "are not");
(void)getchar();
got_eof = feof(stdin);
if ( (got_eof == 0) == (will_get_eof == 0) )
printf ("Carnac was right, as always.\n");
else
printf ("May the fleas of a thousand camels "
"take refuge in your shorts.\n");