在这个代码示例中提到第二个'c = getchar()‘有什么原因吗?
#include <stdio.h>
/* copy input to output; 1st version */
int main(void) {
int c;
c = getchar();
while (c != EOF) {
putchar(c);
c = getchar(); // <-- I mean this one.
}
return 0;
}发布于 2014-12-01 06:33:14
是的,所以它不会破坏EOF。
它读取第一个字符,检查它是否不是EOF,然后putChars它,然后获得另一个字符,回到while循环的顶部,并检查它的not。
发布于 2014-12-01 06:33:47
第二个c = getchar()是读取另一个字符,然后再读取另一个字符,直到EOF满足为止。
发布于 2014-12-01 06:35:18
首先,c = getchar();只能工作一次,但是will循环中的c = getchar();每次都会工作到c != EOF为止。
c = getchar(); // Read value of `c` if `c != EOF` it will enter while loop else it will exit
while (c != EOF) { // checking condition
putchar(c); //printing value of c
c = getchar(); // again getting new value of c and checking in while loop,
//if condition is true it will continue, else it will exit
}https://stackoverflow.com/questions/27222853
复制相似问题