问答详情
源自:4-2 [Linux C语言] 头文件与函数定义分离

求大神, 哪里错了

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

提问者:qq_愿时光安好_04050009 2017-02-06 22:35

个回答

  • qq_平行宇宙_03768374
    2017-02-07 22:00:29

    http://img.mukewang.com/5899d1830001e5bb03710075.jpg运行一下,应该没问题了!