#include
main()
{
FILE *fp;
char ch, st[2000];
if((fp=fopen("c:/log.log","at++")) == NULL)
{
printf("Cannot open file strike any keys exit!");
getch();
exit(1);
}
printf("Input a string:\n");
//gets(st);
scanf("%[^\n]", st);
fputs(st, fp);
fputs("\n",fp);
rewind(fp);
ch = fgetc(fp);
while(ch!=EOF)
{
putchar(ch);
ch=fgetc(fp);
}
printf("\n");
fclose(fp);
getch();
}
scanf函数默认是遇空格便停止继续读字符了,要想让scanf函数继续读可以这样操作:
scanf("%[^\n]", name);
gets(name);