#include <stdio.h>
typedefstruct
{
char num[ 6 ];
char name[8];
int score[6];
float avr;
}STUDENT; // Define the structure
STUDENT student[ 5 ]; // Define the structure array
int main(int argc, constchar * argv[]) {
int i, j, sum;
FILE *fp;
// Enter 5 student information
for (i = 0; i < 3; i++) {
printf ( " Please enter the information of the %d classmate :\n" , i+ 1 );
printf("stuNO:");
scanf("%s", student[i].num);
printf("\nname:");
scanf("%s", student[i].name);
sum = 0;
// find the average score
for (j = 0; j < 3; j++) {
printf("score%d:", j+ 1);
scanf("%d", &student[i].score[j]);
sum += student[i].score[j];
}
student[i].avr = sum/3.0;
printf ( " The average grade of this student :\n%3.2f\n" , student [i] .avr );
}
fp = fopen ( "stud" , "wb+" ); // Open the file
for (i = 0; i < 3; i++) {
// Write student information to file
if (fwrite(&student[i], sizeof(STUDENT), 1, fp) != 1) {
printf("file write error\n");
}
}
fclose (fp); // close the file
}