C语言类型的读文件和写文件
//C语言类型的读文件:fgets(str,n,fp)//读取文件中的字符,存进字符串数组中#include#include/*普通的读取文件(文件已存在字符)*///int main()//{//FILE *stream;char string[]="This is a Test!";//char msg[20];///*open a file for update*///stream = fopen("dump_1.txt","r");///*write string into the file*/fwrite(string,strlen(string),1,stream);//或者先在文件中写入字符串,再从文件中读取///*seek to the start of the file*///fseek(stream,0,SEEK_SET);///*read string from the file*///fgets(msg,50,stream);//printf("%s",msg);//printf("\n");//fclose(stream);//return 0;}///*********写文件************///#include//#define size 1//typedefstruct//{//char name[10];//intnum;//int age;//char addr[15];//}student;//student stu[size];void save()//{//FILE* fp;//inti;//if((fp=fopen("data.txt","w"))==NULL)//{//printf("无法打开此文件!\n");//return ;//}//for(i=0;i#define SIZE 1typedefstruct{ char name[10];intnum;int age; char addr[15]; }student;student stu[SIZE];void save(){ FILE *fp;inti; if((fp=fopen("dat.txt","w"))==NULL) {printf("无法打开此文件!\n"); return; } for(i=0;i