#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 –