使用文件(FILE)输入输出

#include<stdio.h>
#include<stdlib.h>
 struct Stu
{
 char name[10];
 unsigned no,age; 
};
int main()
{
 struct Stu s;
 FILE *fp;
 fscanf(stdin,"%s%d%d",s.name,&s.no,&s.age);
 if((fp=fopen("stu.txt","w"))==NULL)
 {
  puts("error\n");
  exit(1);
 }
 fprintf(fp,"%s\t%d\t%d\n",s.name,s.no,s.age);
 fclose(fp);
 if((fp=fopen("stu.txt","r"))==NULL)
 {
  puts("error\n");
  exit(1);
 }
 fscanf(fp,"%s%d%d",s.name,s.no,s.age);
 fprintf(stdout,"%s\t%d\t%d\n",s.name,s.no,s.age);
 fclose(fp);
 return 0;
}
原文地址:https://www.cnblogs.com/dennisac/p/2244992.html