
#include <stdio.h>
#define SIZE 80

struct student_struct {

    char name[20];
    int status;
    int hw;
    int labs[12];
    int progs[3];
    int mids[2];
    int final;
};

void read_data(struct student_struct *, int);
void write_data(struct student_struct *, int);


main()
{

  struct student_struct student[SIZE];

  read_data(student,SIZE);
  write_data(student,SIZE);

}

void read_data(struct student_struct student1[],int size)
{

FILE *fp;
char filename[40];
int i,j;

printf("Type in the file name:");
scanf("%s",filename);

fp = fopen(filename,"r");

for (i=0;i<size;i++)
{

   fscanf(fp,"%s",student1[i].name);
   fscanf(fp,"%d",&student1[i].status);
   fscanf(fp,"%d",&student1[i].hw);

      for (j=0;j<12;j++) 
          fscanf(fp,"%d",&student1[i].labs[j]);

      for (j=0;j<3;j++)
          fscanf(fp,"%d",&student1[i].progs[j]);

      for (j=0;j<2;j++)
          fscanf(fp,"%d",&student1[i].mids[j]);

   fscanf(fp,"%d",&student1[i].final);
}
fclose(fp);
}

void write_data(struct student_struct student1[],int size)
{

FILE *fp;
char filename[40];
int i,j;

printf("Type in the file name to write:");
scanf("%s",filename);

fp = fopen(filename,"w");

for (i=0;i<size;i++)
{

   fprintf(fp,"%s ",student1[i].name);
   fprintf(fp,"%d ",student1[i].status);
   fprintf(fp,"%d ",student1[i].hw);

      for (j=0;j<12;j++) 
          fprintf(fp ,"%d ",student1[i].labs[j]);

      for (j=0;j<3;j++)
          fprintf(fp ,"%d ",student1[i].progs[j]);

      for (j=0;j<2;j++)
          fprintf(fp,"%d ",student1[i].mids[j]);

   fprintf(fp,"%d \n",student1[i].final);
}
fclose(fp);
}
