|
|
发表于 2012-5-21 23:50:42
|
显示全部楼层
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
int main()
{
FILE *fp;
char ch,st[30];
if((fp=fopen("string.txt","at+"))==NULL)
{
printf("Cannot open file.please strike any key exit!");
getch();
exit(1);
}
printf("please a string:\n");
scanf("%s",st);
fputs(st,fp);
rewind(fp);
fgets(st,20,stdin);
printf("%s",st);
//fclose(fp);/**/
ch=fgetc(fp);
while(ch!=EOF)
{
putchar(ch);
ch=fgetc(fp);
//fgets(st,30,stdin);
//printf("%s",st);
}
printf("\n");
fclose(fp);
}
把fclose(fp)注释掉就可以了,因为fclose(fp)关闭了文件,后面再调用fgetc(fp)自然会出错了 |
|