int x, sum=0;
while(scanf_s("%d", &x) != EOF)
{
sum += x;
}
printf("sum is %d", sum);
return 0;
No matter how input ,I must type CTRL + Z three times to print sum
. I'm using VS 2015.
int x, sum=0;
while(scanf_s("%d", &x) != EOF)
{
sum += x;
}
printf("sum is %d", sum);
return 0;
No matter how input ,I must type CTRL + Z three times to print sum
. I'm using VS 2015.
EOF is a special constant that should only be used when reading from files to check for the end of the file
The End Of the File is what it represents and is a handy way to represent that without remembering what actual value it is.
Pressing Ctrl + Z causes differing behaviors depending on the system. On Linux systems it suspends a process. On Windows, it is interpreted as the Undo command by the kernel. It has no behavior on Mac OS, and is substituted for CMD + Z, which functions similarly to Windows Ctrl + Z.
scanf_s
returns an int
that is the number of characters read from the input.