不懂求指教关于fprintf和fscanf
#include<stdio.h>#include<stdlib.h>
#define MAX 40
int main(void)
{
FILE *fb;
char words[MAX];
if((fb=fopen("words", "a+"))==NULL)
{
fprintf(stdout, "Can't open \"words\" file.\n");
exit(1);
}
puts("Enter words to add to the file; \npress the Enter key at the begining of a line to terminate.");
while(gets(words)!=NULL && words[0]!='\0')
fprintf(fb, "%s", words);
puts("Flie countents");
rewind(fb);
while(fscanf(fb, "%s", words)==1)
puts(words);
if(fclose(fb)!= 0)
fprintf(stderr, "Error closing file\n");
return 0;
}
当我输入I am a[Enter]然后为什么需要再次键入[Enter]程序才会继续(很明确的说不是while(gets(words)!=NULL && words[0]!='\0')这段程序的问题)还有一个问题是为什么输出的结果是
I
am
a
为什么每个单词后会换行