typedef struct Student
{
char name[16];
int age;
double math;
double chinese;
double english;
double wuli;
double huaxue;
double shengwu;
}STU,*p_stu;
int main(int argc, const char *argv[])
{
STU stu[5]={{"yi",18,90,91,92,93,94,95},{"er",19,90,91,92,93,94,95},{"san",20,90,91,92,93,94,95},{"si",21,90,91,92,93,94,95},{"wu",22,90,91,92,93,94,95}};
FILE* fp1 = fopen("./student.txt","w");
if(fp1 == NULL)
{
perror("fp1");
return 1;
}
int i;
for(i=0;i<5;i++)
{
fprintf(fp1,"%s %d %.1lf %.1lf %.1lf %.1lf %.1lf %.1lf\n",stu[i].name,stu[i].age,stu[i].math,stu[i].chinese,stu[i].english,stu[i].wuli,stu[i].huaxue,stu[i].shengwu);
}
fclose(fp1);
FILE* fp1 = fopen("./student.txt","r");
char str[9999]={0};
int j=0;
while(1)
{
char ret=fscanf(fp1,"%c",&str[j]);
if(ret == EOF)
{
break;
}
j++;
}
for(int k=0;k<j;k++)
{
printf("%c",str[k]);
}
fclose(fp1);
return 0;
}
0506作业
于 2024-05-06 21:01:40 首次发布