1.fputc
函数原型:int fputc(int c, FILE *stream);
fputc 功能:把参数 c 指定的字符(一个无符号字符)写入到指定的流 stream 中,并把位置标识符往前移动。例如,下面的代码中char* str = "zhongzifeng zei shuai wo !"把zhongzifeng zei shuai wo !写到text.txt文件里去。
运行结果:
2. fgetc,feof
fgetc函数:
feof函数:
fgetc,feof结合的代码:
#include<stdio.h>#include<string.h>int main(){ FILE *fp; int i; char c; fp = fopen("./text.txt","r"); while(!feof(fp))//表示没有读到文件结尾时继续循环 { c = fgetc(fp); printf("%c",c); } printf("n"); fclose(fp); return 0;}运行结果: