cex_13_5.c

来自「C程序学习者学习文件操作的好讲义,包含例题,这个讲义是本人清手做的,花了很长时间」· C语言 代码 · 共 27 行

C
27
字号
#include "stdlib.h"
#include "stdio.h"
struct student_type
{
  char name[10];
  int num;
  int age;
  char sex;
}stud[10];
void main()
{
  int i;
  FILE * fp;
  if ((fp=fopen("stud_dat", "rb")) == NULL)
  {
    printf("can not open file\n");
    exit(0);
  }
  for(i=0; i<10; i += 2)
   {
    fseek(fp, i*sizeof(struct student_type), 0);
    fread(&stud[i], sizeof(struct student_type), 1, fp);
    printf("%s,%d,%d,%c\n",stud[i].name, stud[i].num, stud[i].age, stud[i].sex);
   }
  fclose(fp);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?