#include <stdio.h>
#include <stdlib.h>
#define N 50
struct Student
{
char ID[20];
char name[30];
int age;
double score;
};
int main()
{
FILE *fp;
struct Student st[N];
int n,i;
printf("Please input the number of students :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("please input iD");
scanf("%s",&st[i].ID);
printf("please input name");
scanf("%s",&st[i].name);
printf("please input age");
scanf("%d",&st[i].age);
printf("please input score");
scanf("%lf",&st[i].score);
}
fp=fopen("d:\\Infor.dat","wb");
if(fp==0)
{
printf("file error");
exit(1);
}
for(i=0;i<n;i++)
{
fwrite(st,sizeof(struct Student),n,fp);
}
fclose(fp);
return 0;
}
#include <stdlib.h>
#define N 50
struct Student
{
char ID[20];
char name[30];
int age;
double score;
};
int main()
{
FILE *fp;
struct Student st[N];
int n,i;
printf("Please input the number of students :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("please input iD");
scanf("%s",&st[i].ID);
printf("please input name");
scanf("%s",&st[i].name);
printf("please input age");
scanf("%d",&st[i].age);
printf("please input score");
scanf("%lf",&st[i].score);
}
fp=fopen("d:\\Infor.dat","wb");
if(fp==0)
{
printf("file error");
exit(1);
}
for(i=0;i<n;i++)
{
fwrite(st,sizeof(struct Student),n,fp);
}
fclose(fp);
return 0;
}