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

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;
}

 

posted @ 2021-06-11 09:04  小鲨鱼2018  阅读(147)  评论(0编辑  收藏  举报