putchar无法再屏幕上输出,请帮忙解答下
原程序如下,就是在while语句那里无法输出到屏幕上,只是推断while语句没气作用,但不知道为什么没起作用,请帮忙解答下,谢啦。#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/*const int LENGTH = 80;*/
#define LENGTH 80
int main(void)
{
char mystr[LENGTH];
int lstr = 0,i = 0;
int mychar = 0;
FILE *pfile = NULL;
char *filename = "F:\\myfile.txt";
printf("\nEnter an interesting sting of less than 80 characters:");
fgets(mystr,LENGTH,stdin);
pfile = fopen(filename,"w");
if(!pfile)
{
printf("Error opening %s for writing.Program terminated.",filename);
exit(1);
}
lstr = strlen(mystr);
for( i = lstr-1; i >= 0;i--)
fputc(mystr[i],pfile);
fclose(pfile);
if(!pfile)
{
printf("Error opening %s for reading.Program terminated.",filename);
exit(1);
}
while((mychar = fgetc(pfile)) != EOF)
putchar(mychar);
putchar('\n');
fclose(pfile);
/*remove(filename);*/
return 0;
}
就是能往文件里写,但在while那里应该往屏幕上输出的,怎么就是显示不了呢