#include<stdio.h>
void main() {
FILE *fp;
char ch;
fp = fopen("input.txt", "w");
printf("Enter data");
while ((ch = getchar()) != EOF) {
putc(ch, fp);
}
fclose(fp);
fp = fopen("input.txt", "w");
while ((ch = getc(fp)) != EOF) {
printf("%c", ch);
}
fclose(fp);
}
第一个while
循环如何停止从用户输入? 由于存在EOF
作为条件。EOF函数如何在c中工作?
否则我需要use
for循环?
必须将'ch' **定义为'int'。 – pmg
2nd'fp = fopen(“input.txt”,“w”);':'“w”' - >'“r”' – BLUEPIXY
同样的问题? http://stackoverflow.com/questions/1782080/what-is-eof-in-the-c-programming-language –