Is there any reason of the second 'c = getchar()' mention in this code example?
#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;
}
getchar()reads the first time input character.getchar()keeps on reading next input(s), untill aEOFIn other words, the purpose of
while (c != EOF)is to keep on checking whether thecisEOFor not. ifcis not changed, then thewhile()loop is meaningless, isn't it? The secondgetch()is responsible for chnaging the value ofcin each iteration.