用C打印文件内容
这是一个用C语言打印文件内容的示例,
假设我们有“new.txt”文件,其中包含以下内容。
0,hell!o 1,hello! 2,gfdtrhtrhrt 3,demo
现在,让我们来看一个例子。
示例
#include<stdio.h>
#include<conio.h>
void main() {
FILE *f;
char s;
clrscr();
f=fopen("new.txt","r");
while((s=fgetc(f))!=EOF) {
printf("%c",s);
}
fclose(f);
getch();
}输出结果
0,hell!o 1,hello! 2,gfdtrhtrhrt 3,demo
在上面的程序中,我们有一个文本文件“new.txt”。文件指针用于打开和读取文件。它正在显示文件的内容。
FILE *f;
char s;
clrscr();
f=fopen("new.txt","r");
while((s=fgetc(f))!=EOF) {
printf("%c",s);
}