scanf and EOF
i have studied this following statement from a book "Each scanning function returns EOF if it encounters end-of-file before any conversion; otherwise it returns the number of successful conversions that were stored."
To test this i have written the following code
i have given directly EOF character Ctrl + Z followed by return key as input. The output is ret = 1 instead of -1. where am i doing the mistake? i know i am doing a mistake some where.
int main(int argc, char *argv)
ret = scanf("%c",&c);
thanks in advance,
What OS are you on? In Cygwin as soon as I hit CTRL D it stops and produces a -1. I don't have to hit enter. Unix uses CTRL D, DOS uses CTRL Z.
Should ret not be 1? Scanf returns the number of items read if it scanned correctly.
i tested first on Windows XP and the returned value is 1 when i entered CTRL Z followed by enter key. When i test on windows 7 and when i enter CTRL Z followed by enter key it returns -1. I need to test it again on windows XP, right now i do not have access to that PC, may be i will retest tomorrow and let you know.
sorry i missed the following point. i am using the QT software to write C programs.
thanks and regards,