用 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);
}
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP