GetChar () migration problem

xiaoxiao2021-03-06  41

The following program is normal on some machines, but not normal on some machines, why?

int main ()

{

Char C;

While ((c = getchar ())! = EOF)

PUTCHAR (C);

Return 0;

}

A: Because getc and getchar returned, it is intellectual, not a character type. Since EOF is often defined as -1, if the system uses a symbolic character type, it can work. If you are using an unsigned character type, the value returned by getchar will never be -1 after saving to c, and the program will fall into an infinite loop.

转载请注明原文地址:https://www.9cbs.com/read-64136.html

New Post(0)