c语言中fgetc函数:显示文件内容

时间:2021-06-11 18:30:11   收藏:0   阅读:0

1、显示a.txt文件的内容

#include <stdio.h>

int main(void)
{
    FILE *fp;
    int ch;
    char filename[FILENAME_MAX];
    printf("Please input the filename: "); scanf("%s", filename);
    
    if((fp = fopen(filename, "r")) == NULL)
        printf("\aFile oprn failed.\n");
    else
    {
        while((ch = fgetc(fp)) != EOF)
            putchar(ch);
        fclose(fp);
    }
    return 0;
}

技术图片

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!