C语言编写函数~~~功能是:文本文件显示

请帮忙用C语言编写一个函数~~~功能是“文本文件显示”~~~谢谢~~
2024-12-22 19:42:02
推荐回答(2个)
回答1:

#include "stdio.h"
#include "stdlib.h"
void main()
{
FILE *fp;
if((fp=fopen("C:/a.txt","r"))==NULL)
{
printf("cannot be open!\n");
exit(1);
}
char str[81];
fgets(str,81,fp);
while(!feof(fp)){
printf("%s",str);
fgets(str,80,fp);
}
fclose(fp);
}

回答2:

#include"stdio.h"
main()
{
FILE *fp;
if((fp=fopen("abc.txt","r"))==NULL)
{
printf("cannot be open!\n");
exit(1);
}
fputc(fgetc(fp),stdout);
}