需要操作制定的文件,首先需要获取文件的文件描述符(句柄):fd
=
fopen("test.txt","w")
2.
使用fprintf(),或者fputs()函数将数据格式化写入该文本
#include
main()
{
FILE *f
f=fopen("wenzhang.txt","w")
fprintf(f,"this is a c program !")
fclose(f)
}
程序1(显示in.txt):#include<stdio.h>
main(){
printf("in.txt")
}
程序2(显示in.txt文件里面的内容):
#include<stdio.h>
main(){
FILE *FP
char s[1024]
fp=fopen("in.txt","r")
while(!feof(fp)){
fgets(fp,s)
printf("%s\n",s)
}
fclose(fp)
}