有以下程序
#include <stdio.h>
#include <stdlib.h>
main()
{ FILE *fp;
char ch,str[5];
if((fp=fopen("file.txt","wb+"))==NULL)
{ printf("error!\n"); exit(0); }
ch=getchar();
while( ch!='!')
{ fputc(ch,fp);
ch=getchar();
}
rewind(fp);
do{
fgets(str,4,fp);
puts(str);
}
while(!feof(fp));
fclose(fp);
}
程序运行时输入:c:\\test!<回车>,则程序的输出结果是
A.c:\
\te
st
B.c:\ test
C.c: tes
t
D.c:\t
est