#include
# define N 100
Int current;
Typedef struct student
{
Char * num.
Char * nam;
Float Chinese;
Float English;
Float math;
Double business;
float sum;
} STU.
STU STU [N].//define structure array
Int main () {
Int I, j, k, r, m, n, t;
Int pass;
Float hold, temp, temp1, temp4;
Char * temp2;
Char * temp3;
Double temp5.
For (n=0; n
Stu [n]. Nam=malloc (5 * sizeof (char));
}
//for structure dynamically allocated memory
Printf (" please enter the number of students: \ n ");
The scanf (" % d ", & amp; The current);
for(i=0; i
The scanf (" % s ", & amp; Stu [I] num);
Printf (" please enter the student's name: \ n ");
The scanf (" % s ", & amp; Stu [I]. Nam);
Printf (" please enter the student's language result: \ n ");
The scanf (" % f ", & amp; Stu [I]. Chinese);
Printf (" please enter the student's mathematics result: \ n ");
The scanf (" % f ", & amp; Stu [I]. Math);
Printf (" please enter the student's English: \ n ");
The scanf (" % f ", & amp; Stu [I]. English);
}//entry student achievement
for(j=0; j
Printf (". An average grade of students % s: % 2 f \ n ", stu [j]. Journal of nam, stu [j]. Journal of business);
}//output each student's grade point average
For (k=0; K
Combined for printf (" % s: % f \ n ", stu [k]. Nam, stu [k]. Sum);
}//output each student's total grade
For (pass=0; Pass
Stu [t]. Chinese=stu [t + 1] Chinese;
Stu [t + 1] Chinese=hold;//the language
Temp=stu [t]. English;
Stu [t]. English=stu [t + 1] English.
Stu [t + 1] English=temp;//English
Temp1=stu [t]. Math;
Stu [t]. Math=stu [t + 1]. Math.
Stu [t + 1] math=temp1;//mathematical
Temp2=stu [t]. Num;
Stu [t]. Nam=stu [t + 1] nam;
Stu [t + 1]. Nam=temp2;//student id
Temp3=stu [t]. Nam;
Stu [t]. Nam=stu [t + 1] nam;
Stu [t + 1]. Nam=temp3;//name
Temp4=stu [t]. Sum;
Stu [t] sum=stu [t + 1] sum;
Stu [t + 1] sum=temp4;//total score
Temp5=stu [t]. Business;
Stu [t]. Business=stu [t + 1] business;
Stu [t + 1] business=temp5;//average
}
}
}//bubble sort of total score from high to low order
Printf (" according to the total score from high to low output information for students: \ n ");
For (r=0; R
Stu [r]. Nam, stu [r]. Num, stu [r]. Chinese, stu [r]. English, stu [r]. Math, stu [r]. Sum, stu [r]. Business);
}
For (m=0; M
Free (stu [m]. Nam);
}
return 0;
}
CodePudding user response:
There is a problem here: the scanf (" % s ", & amp; Stu [I] num); To the scanf (" % s ", stu [I] num);Stu [n]. Num=malloc (10 * sizeof (char)); This is an error? A void * should be cast
CodePudding user response:
And the next post code, get format, otherwise a lot of people don't seeCodePudding user response:
For (n=0; nStu [n]. Num=malloc (10 * sizeof (char));
Stu [n]. Nam=malloc (5 * sizeof (char));
}
//for structure dynamically allocated memory
Printf (" please enter the number of students: \ n ");
The scanf (" % d ", & amp; The current);
Discuss the
order to below,
Printf (" please enter the number of students: \ n ");
The scanf (" % d ", & amp; The current);
For (n=0; nStu [n]. Num=malloc (10 * sizeof (char));
Stu [n]. Nam=malloc (5 * sizeof (char));
}
Well, under the name here also change
Remove & amp;
Printf (" please enter the student's student id: \ n ");
The scanf (" % s ", stu [I] num);
Printf (" please enter the student's name: \ n ");
The scanf (" % s ", stu [I]. Nam);
CodePudding user response:
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.htmlI hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html