Home > Back-end >  Use while ((c=getchar ()! EOF))={putchar (c); Why} to output the code
Use while ((c=getchar ()! EOF))={putchar (c); Why} to output the code

Time:10-06

The code below
#include
Int main () {
Int c;
While ((c=getchar ()! EOF))={
Putchar (c);
}
return 0;
}
Why run results is such,
Where is the code wrong?

CodePudding user response:

#include
Int main () {
Int c;===="" into a char c;
While ((c=getchar ()! EOF))====="" to the while ((c=getchar ())!=(EOF)
{
Putchar (c);
}
return 0;
}

CodePudding user response:

While ((c= getchar ()!=EOF ))
Because this sentence
Getchar ()! EOF before you didn't Ctrl + Z=the input character is not EOF, so the judgment is always 1
C=1
Putchar (1)
What is it you see 1 ASCII corresponds to know

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

CodePudding user response:

Equals the lowest priority, so is the calculation to the right of the first, in the assigned to c

CodePudding user response:

Assignment=priority below!=so getchar ()!=EOF to perform first, then put the result of 1 assignment c, so every time the output putchar (1); Is the code,
  • Related