My system is centos5.5 and the compiler is GCC 2.5.
The procedure is as follows:
// Function of the program: verification expression getchar ()! = Whether the value of EOF is 0 or 1.
# Include <stdio. h>
Main ()
{
Int C;
While (C = getchar ()! = EOF )//! The = Priority is higher than the = priority, so the expression is combined from right to left.
Printf ("% d \ n", C );
Printf ("% d-at EOF \ n", C );
}
After GCC compilation, generate the. Out file.
./A. Out: Enter the following data:
2 press ENTER
Output:
1
1
How can two 1 s be output? Think about it, the carriage return is also a character, so it is actually two inputs, so the output is two 1. It also indicates that when the input is not equal to EOF, the expressionGetchar ()! = EOFThe value is 1.
Enter:
Enter
Output:
1
Enter-1 and press Enter.
Output:
1
1
1
'-', 1, and 'Carriage return 'are three characters in total, SO 3 are output.
How can I end the input at this time? In my system, press Ctrl + D.
Press Ctrl + D, which is equivalent to the input EOF, and the output is:
0-at EOF
This indicates that when the input is equal to EOF, the expressionGetchar ()! = EOFThe value is 0.
Because EOF is defined in the header file <stdio. h>, you can add the following code to the end of the program to view the value of EOF:
Printf ("% d \ n", EOF );
The output result is-1.
Well, make a little progress every day.