帮忙这程序错在哪

来源:百度知道 编辑:UC知道 时间:2024/06/23 22:13:29
#include <stdio.h>
#include <stdlib.h>

typedef struct t_student {
unsigned id;
float mid_term_score;
float end_term_score;
float average_score;
} STUDENT;

int main()
{
unsigned stu_numbers=0;
unsigned i;

printf("Please input numbers of the students: ");
scanf("%d", &stu_numbers);

STUDENT *p_stu = (STUDENT*) malloc( stu_numbers*sizeof(STUDENT) );
if(!p_stu)
printf("\nMemery ERROR !\n");

for(i=0; i<stu_numbers; i++)
{
printf("\nPlease input the id of student %d : ", i+1);
scanf("%d", &( (p_stu+i)->id ));
printf("Please input the mid_term_score of student %d : ", i+1);
scanf("%f", &( (p_stu+i)->mid_term_score ));
printf("Please input the end_term_score of student %d : ", i+1);
sc

#include <stdio.h>
#include <stdlib.h>

typedef struct t_student {
unsigned id;
float mid_term_score;
float end_term_score;
float average_score;
} STUDENT;

int main()
{
unsigned stu_numbers=0;
unsigned i;
float temp;/*定义一个实型变量,以便于对结构体中输入实型数据,C编译器在用scanf输入实型变量给结构体时,常有bug,你只需定义一个变量,然后把变量值赋值给结构体元素就行了,具体在后面的scanf语句中标注,你自己看吧*/
STUDENT *p_stu;/*此处,要先对p_stu进行声明,才能赋值,你的程序声明在语句后,编译是不会通过的*/
printf("Please input numbers of the students: ");
scanf("%d", &stu_numbers);

p_stu = (STUDENT*) malloc( stu_numbers*sizeof(STUDENT) );
if(!p_stu)
printf("\nMemery ERROR !\n");

for(i=0; i<stu_numbers; i++)
{
printf("\nPlease input the id of student %d : ", i+1);
scanf("%d", &( (p_stu+i)->id ));
printf("Please input the mid_term_score of student %d : ", i+1);