#include <stdio
c4droid吧
全部回复
仅看楼主
level 11
#include <stdio.h>
#include <stdlib.h>
#define MAX 40
int main(void)
{
FILE *fp;
char words[MAX];
if ((fp = fopen("words", "a+")) == NULL)
{
fprintf(stdout,"Can't open \"words\" file.\n");
exit(1);
}
puts("Enter words to add to the file; press the Enter");
puts("key at the beginning of a line to terminate.");
while (gets(words) != NULL && words[0] != '\0') //1
fprintf(fp, "%s ", words);
puts("File contents:");
rewind(fp); /* 回到文件开始 */
while (fscanf(fp,"%s",words) == 1)
puts(words); //2
if (fclose(fp) != 0)
fprintf(stderr,"Error closing file\n");
return 0;
}
这个程序是从哪里开始读取输入的呢?是1还是2处?那个回到文件开始又是什么意思?
2017年09月07日 11点09分 1
level 14
gets是读,所以1,rewind把文件指针重设到开头位置。
2017年09月09日 12点09分 3
多谢啦
2017年09月18日 15点09分
1