qixin622
#include<stdlib.h>
#include
<stdio.h>
#include
<conio.h>
#define N 4
extern unsigned _floatconvert;
#pragma extref _floatconvert
struct student
{
  
int num;
  
char name[10];
  
char sex;
  
int age;
  
float grade;
}stu[N]
={{101,"Zhang",\'M\',19,95.6},
         {
102,"Wang",\'F\',18,92.4},
         {
103,"Zhao",\'M\',18,91.5},
         {
104,"Li",\'F\',17,98.7}};
void save()
{
  FILE 
*fp;
  
int i;
  
if((fp=fopen("d:\\student.dat","wb"))==NULL)
  {
    printf(
"Cannot open this file!\n");
    
return;
  }
  
for(i=0;i<N;i++)
    
if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)
      printf(
"file write error!\n");
  fclose(fp);
}
void read()
{
  FILE 
*fp;
  
int i;
  
struct student stud[N];
  
if((fp=fopen("d:\\student.dat","rb"))==NULL)
  {
    printf(
"Cannot open the file!\n");
    
return;
  }
  
for(i=0;i<N;i++)
  {
    fread(
&stud[i],sizeof(struct student),1,fp);
    printf(
"%d\t%s\t%c\t%d\t%.1f\n",stud[i].num,stud[i].name,stud[i].sex,stud[i].age,stud[i].grade);
  }
  fclose(fp);
}

void main()
{
  clrscr();
  save();
  read();
  getch();
}

分类:

技术点:

相关文章:

  • 2021-09-17
  • 2021-09-17
  • 2021-08-16
  • 2021-08-16
  • 2021-09-07
  • 2021-09-19
  • 2021-09-27
  • 2021-12-15
猜你喜欢
  • 2018-09-09
  • 2021-08-16
  • 2021-11-16
  • 2021-09-07
  • 2021-10-20
  • 2021-08-16
  • 2021-08-16
  • 2021-08-16
相关资源
相似解决方案