Home > Back-end >  C language program, there are no errors, but can't run it out
C language program, there are no errors, but can't run it out

Time:06-03

#include
#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; 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);

for(i=0; iPrintf (" please enter the student's student id: \ n ");
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; jStu [j]. Journal of business=(stu [j]. Chinese + stu [j]. Journal of math + stu [j]. Journal of English)/3.0;
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; KStu [k]. Sum=(stu [k]. Chinese + stu [k]. Math + stu [k]. English);
Combined for printf (" % s: % f \ n ", stu [k]. Nam, stu [k]. Sum);
}//output each student's total grade

For (pass=0; PassFor (t=0; TIf (stu [t]. SumHold=stu [t]. Chinese;
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; RPrintf (" student student number: student's name: % s to % s language: English: % f, % f mathematics: % f score: %. 2 lf average: % f \ n ",
Stu [r]. Nam, stu [r]. Num, stu [r]. Chinese, stu [r]. English, stu [r]. Math, stu [r]. Sum, stu [r]. Business);
}
For (m=0; MFree (stu [m]. Num);
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 see

CodePudding 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.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related