fputc()函数用于将单个字符写入文件。它将字符输出到流。
语法:
int fputc(int c, FILE *stream)
示例:
#include<stdio.h>main(){ FILE *fp; fp = fopen("file1.txt", "w");//opening file fputc('a',fp);//writing single character into file fclose(fp);//closing file }
file1.txt
a
fgetc()函数从文件返回单个字符。它从流中获取一个字符。它在文件末尾返回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
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
Spring Cloud 微服务项目实战 -〔姚秋辰(姚半仙)〕