我正在尝试将一些数据输入到文件中,然后在控制台上读取并打印它。
这是我的代码:
fp=fopen("user1","w+");
char line[1000];
char *c;
//write on file
while(1)
{
fgets(line,sizeof(line),stdin);
if(strcmp(line,":wq\n")==0) //input ends when user enters :wq
break;
else
fputs(line,fp);
}
//read from file
fflush(stdin);
while(1)
{
c=fgetc(fp);
if(c==EOF)
break;
else
printf("%ch",c);
}
我输入数据为
比萨
:wq
输出:
h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h h
问题是什么?