#include <stdio.h>
#include<ctype.h>
int read(); 请问一下,这里形参应该怎样写啊?
int main()
{
struct student
{
char name[20];
int id;
float class1;
float class2;
float class3;
};
struct student stu[5];
int i;
float ave[5],total=0;
char NAME,ID,AVE;
FILE *outfile = fopen("stud.txt","w");
FILE *infile;
for(i=0;i<5;i++){
printf("Please input the %d student\n",i+1);
printf("Name:");
scanf("%s",&stu[i].name);
printf("ID:");
scanf("%d",&stu[i].id);
printf("Class1:");
scanf("%f",&stu[i].class1);
printf("Class2:");
scanf("%f",&stu[i].class2);
printf("Class3:");
scanf("%f",&stu[i].class3);
total+=stu[i].class1+stu[i].class2+stu[i].class3;
ave[i]=total/3.0;
}
printf(" %-10s%-10s%-10s\n","NAME","ID","AVE");
fprintf(outfile," %-10s%-10s%-10s\n","NAME","ID","AVE");
for(i=0;i<5;i++)
{
// printf("The %d student:%-10s%-10d%-10.2f",i+1,stu[i].name,stu[i].id,ave[i]);
fprintf(outfile,"The %d student:%-10s%-10d%-10.2f\n",i+1,stu[i].name,stu[i].id,ave[i]);
//printf("\n");
}
read(); 这里的实参又应该这样写啊?
return 0;
}
int read()
{ FILE *outfile;
static char name[20];
float i,j,k,m;
outfile=fopen("stud.txt","r");
if(outfile==NULL)
printf("Failed to open the file!");
else
while (fscanf(outfile,"The %d student:%s%d%f",name,&i,&j,&k)!=EOF)
printf("The %d student:%-10s%-10d%-10.2f\n",i,name,j,k);
fclose(outfile);
return 0;
}