fputc()函數(shù)用于將單個(gè)字符寫入文件。它將字符輸出到流。
語法:
int fputc(int c, FILE *stream)
#include <stdio.h>
void main(){
FILE *fp;
fp = fopen("file1.txt", "w");//打開文件
fputc('a',fp);//將單個(gè)字符寫入文件
fclose(fp);//關(guān)閉文件
}file1.txt
a
fgetc()函數(shù)從文件返回單個(gè)字符。它從流中獲取一個(gè)字符。它在文件末尾返回EOF。
語法:
int fgetc(FILE *stream)
#include<stdio.h>
#include<conio.h>
void main(){
FILE *fp;
char c;
clrscr();
fp=fopen("myfile.txt","r");
while((c=fgetc(fp))!=EOF){
printf("%c",c);
}
fclose(fp);
getch();
}myfile.txt
this is simple text message