Home > Back-end >  For help, the program output interface is blank, and the student2. TXT is empty, is where there is a
For help, the program output interface is blank, and the student2. TXT is empty, is where there is a

Time:09-20

Subject content: a class there are 10 students, set up student structure types, including student id, name, 3 course results, write a program to read the text file has prepared student1. TXT, to structure an array variable assignment, calculate the average per student scores and rankings, the results of the output to the screen at the same time saved to student2. TXT file, the source program as answers submitted, after the program is running will generate student2. TXT file upload as attachment,
(student1. TXT has to provide, directly downloaded from the attachment),
Student1:
Zhao 201701 29.8 85.4 65.4
201702 qian 96.5 87.5 65.4
201703 sun 85.4 65.4 84.6
201704 li, 63.4 95.4 86.3
Zhou 201705 65.9 84.6 97.5
201706 wu, 39.8 85.4 75.4
Zheng 201707 96.5 82.5 75.9
201708 wang, 75.4 85.4 94.6
201709 feng 73.4 95.4 56.3
2017010 Chen, 75.9 74.6 77.5

 # include & lt; Stdio. H> 
#include
Struct student
{
Long num.
Char name [10].
Float score [3].
} ml [10];
Void Mr (float aver [], int rank [])
{
Int I, j, a;
for(i=0; i<10; I++)
{
A=1;
for(j=0; J<10; J++)
{
If (aver [I] A=a + 1;
}
Rank [I]=a;
}
}
Int main ()
{
The FILE * fp1, * fp2;
Int I, rank [10].
Float aver [10].
If ((fp1=fopen (" E: \ \ student1 TXT ", "r"))==NULL)
{
Printf (" unable to open file \ n ");
exit(0);
}
Fp2=fopen (" E: \ \ student2 TXT ", "w");
for(i=0; i<10; I++)
Fscanf (fp1, % f "% ld % s % f % f", ml [I] num, ml [I]. Name, ml [I] score [0], ml [I] score [1], ml [I] score [2]).
for(i=0; i<10; I++)
{
Aver [I]=(ml [I] score ml [0] + [I] score [1] + ml [I] score [2])/3.0;
}
Mr (aver, rank);
for(i=0; i<10; I++)
Fprintf (fp2, "% - 9-10 ld % s % 5.1 f % 5.1 f % % 8.1 f % 10.1 f - d \ n", ml [I] num, ml [I]. Name, ml [I] score [0], ml [I] score [1], ml [I] score [2], aver [I], rank [I]);
The fclose (fp1);
The fclose (fp2);
return 0;
}

CodePudding user response:

 # include & lt; Stdio. H> 
#include

Struct student
{
Long num.
Char name [10].
Float score [3].
} ml [10];

Void Mr (float aver [], int rank [])
{
Int I, j, a;
for(i=0; i<10; I++)
{
A=1;
for(j=0; J<10; J++)
{
If (aver [I] A=a + 1;
}
Rank [I]=a;
}
}
Int main ()
{
The FILE * fp1, * fp2;
Int I, rank [10].
Float aver [10].
If ((fp1=fopen (" E: \ \ student1 TXT ", "r"))==NULL)
{
Printf (" unable to open file \ n ");
exit(0);
}
Fp2=fopen (" E: \ \ student2 TXT ", "w");
If (! Fp2) {
Printf (" unable to open file \ n ");
exit(0);
}

# if 0
for(i=0; i<10; I++)
//fscanf (fp1, % f "% ld % s % f % f", ml [I] num, ml [I]. Name, ml [I] score [0], ml [I] score [1], ml [I] score [2]).
Fscanf (fp1, % f "% ld % s % f % f", & amp; Ml [I]. Num, ml [I]. Name, & amp; Ml [I] score [0], & amp; Ml [I] score [1], & amp; Ml [I] score [2]);
for(i=0; i<10; I++)
{
Aver [I]=(ml [I] score ml [0] + [I] score [1] + ml [I] score [2])/3.0;
}
# the else
for(i=0; i<10; I++) {
//fscanf (fp1, % f "% ld % s % f % f", ml [I] num, ml [I]. Name, ml [I] score [0], ml [I] score [1], ml [I] score [2]).
Fscanf (fp1, % f "% ld % s % f % f", & amp; Ml [I]. Num, ml [I]. Name, & amp; Ml [I] score [0], & amp; Ml [I] score [1], & amp; Ml [I] score [2]);
Aver [I]=(ml [I] score ml [0] + [I] score [1] + ml [I] score [2])/3.0;
}
# endif
Mr (aver, rank);
for(i=0; i<10; I++)
Fprintf (fp2, "% - 9-10 ld % s % 5.1 f % 5.1 f % % 8.1 f % 10.1 f - d \ n", ml [I] num, ml [I]. Name, ml [I] score [0], ml [I] score [1], ml [I] score [2], aver [I], rank [I]);
The fclose (fp1);
The fclose (fp2);
return 0;
}

For your reference ~

CodePudding user response:

The
reference 1/f, confident boy reply:
 # include & lt; Stdio. H> 
#include

Struct student
{
Long num.
Char name [10].
Float score [3].
} ml [10];

Void Mr (float aver [], int rank [])
{
Int I, j, a;
for(i=0; i<10; I++)
{
A=1;
for(j=0; J<10; J++)
{
If (aver [I] A=a + 1;
}
Rank [I]=a;
}
}
Int main ()
{
The FILE * fp1, * fp2;
Int I, rank [10].
Float aver [10].
If ((fp1=fopen (" E: \ \ student1 TXT ", "r"))==NULL)
{
Printf (" unable to open file \ n ");
exit(0);
}
Fp2=fopen (" E: \ \ student2 TXT ", "w");
If (! Fp2) {
Printf (" unable to open file \ n ");
exit(0);
}

# if 0
for(i=0; i<10; I++)
//fscanf (fp1, % f "% ld % s % f % f", ml [I] num, ml [I]. Name, ml [I] score [0], ml [I] score [1], ml [I] score [2]).
Fscanf (fp1, % f "% ld % s % f % f", & amp; Ml [I]. Num, ml [I]. Name, & amp; Ml [I] score [0], & amp; Ml [I] score [1], & amp; Ml [I] score [2]);
for(i=0; i<10; I++)
{
Aver [I]=(ml [I] score ml [0] + [I] score [1] + ml [I] score [2])/3.0;
}
# the else
for(i=0; i<10; I++) {
//fscanf (fp1, % f "% ld % s % f % f", ml [I] num, ml [I]. Name, ml [I] score [0], ml [I] score [1], ml [I] score [2]).
Fscanf (fp1, % f "% ld % s % f % f", & amp; Ml [I]. Num, ml [I]. Name, & amp; Ml [I] score [0], & amp; Ml [I] score [1], & amp; Ml [I] score [2]);
Aver [I]=(ml [I] score ml [0] + [I] score [1] + ml [I] score [2])/3.0;
}
# endif
Mr (aver, rank);
for(i=0; i<10; I++)
nullnullnullnullnullnullnull
  • Related