• 文件操作学习笔记 whl


    #include <stdlib.h>
    #include <stdio.h>
    typedef struct student
    {   
     char name[100];
     int num;
     int score;
    }STUDENT;
    STUDENT stu[ ]={"zhangsan",01,90,"lisi",02,95,"wangwu",03,95};
    void Wf()
    {
     FILE *fp;
     fp = fopen("stu.txt","wb");
     int i;
     for(i=0;i<3;i++)
     {
      fseek(fp,sizeof(STUDENT)*i,SEEK_SET);
      fwrite(&stu[i],sizeof(STUDENT),1,fp);
     }
     fclose(fp);
    }
    void Rf()
    {
     STUDENT temp[3];

     FILE *fp;
     fp = fopen("stu.txt","rb");
     int i;
     for(i=0;i<3;i++)
     {
      fseek(fp,sizeof(STUDENT)*i,SEEK_SET);
      fread(&temp[i],sizeof(STUDENT),1,fp);
     }
     fclose(fp);
    }
    void main()
    {  
     Wf();
     Rf();
     system("pause");
    }

  • 相关阅读:
    如何为创建大量实例节省内存?
    4-5
    4-6
    4-4
    4-3
    4-2
    3-11
    4-1
    3-10
    3-8
  • 原文地址:https://www.cnblogs.com/whl2012/p/2736582.html
Copyright © 2020-2023  润新知