第1个回答 推荐于2018-02-27
#include "
stdio.h"void main()
{
FILE *fp;
if((fp=fopen("f1.txt","r"))==NULL)
{
printf("无法打开文件\n");
return ;
}
while(!feof(fp))
{
putchar(fgetc(fp));
}
printf("\n\n显示完毕\n");}
本回答被网友采纳
第2个回答 2017-07-07
#include <iostream>
#include <cstdio>
using namespace std;
void print(char *p)
{
while(1)
{
if(*p!=0)
printf("%c",*p++);
else
break;
}
return;
}
int main()
{
string a;
a=freopen("xx.txt",r,stdin)//这是一个名字叫做“xx”的txt文档
print("a");
return 0;
}
//应该是这样吧……
第3个回答 2017-07-31
假设文本文件data.txt的内容是
abcde
12345
#include<stdio.h>
void main() { FILE *fp; char buffer[256];
if ( fp=fopen("data.txt","r") ) {
while ( !feof(fp) ) {
fgets(buffer,255,fp); printf("%s\n",buffer);
}
fclose(fp);
} else printf("无法打开文本文件读取。\n");
}
第4个回答 2017-08-02
int main(){
FILE* file=fopen("D:\\report_data2.txt","r");
if(file==NULL){
return 0;
}
char ch;
while((ch=fgetc(file))!=EOF){
printf("%c",ch);
}
fclose(file);
printf("\n");
}