求大神, 哪里错了
#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,哪里错了