qq_愿时光安好_04050009
2017-02-06 22:35
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int ch;
FILE * fp;
char fname[50];
printf("Please enter file nmae to open: ");
while(scanf("%s", fname)== 1)
{
int count = 0;
fp = fopen(fname, "r");
if (fp = NULL) //地址为空,文件不存在 —失败
{
printf("Failed to open the file.\n");
exit(1);
}
while((ch = getc(fp)) != EOF)
{
putchar(ch);
++count; //统计字符数
}
printf("\ncharacter count = %d\n", count);
printf("Please enter next file nmae to open: ");
fclose(fp);
}
return 0;
}
无法显示文件内容,还有统计的字符数目, 这个一直输出0,哪里错了
运行一下,应该没问题了!
Linux C语言编程基本原理与实践
203963 学习 · 451 问题
相似问题