嗨,我有以下代码
#include <stdio.h>
#include <stdlib.h>
#include <process.h>
#include <conio.h>
int main()
{
FILE *fp;
char c=' ';
fp=fopen("E:\data.txt","w");
if(fp==NULL)
{
printf("Cannot open file");
exit(1);
}
printf("Write data & to stop press '.' :");
while(c!='.')
{
c=getche();
fputc(c,fp);
}
fclose(fp);
printf("\nContents Read:");
fp=fopen("E:\data.txt","r");
while(!feof(fp));
printf("%c",getc(fp));
}
执行上述代码时,我有以下输出
输出:
Write data & to stop press '.' :writing data into the file.
Contents Read:
输出不显示我输入的内容。
请帮助我哪里出错了。