English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
이것은 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); }