为什么这个输入完n后就没有了?

img

img

img

img


要求用指针和结构体,有没有大能能来看看它呀。它这个输入完n是多少就没有下文了,直接没了。

好几处错误,函数体里也有错误:

img


修改如下,供参考:

#include <stdio.h>
#include <stdlib.h>
/***********Begin***********/
struct STUDENT{
   long num;
   char name[13];
   float score[4],total,average;

};
/***********End*************/


void Input(struct STUDENT *stud, int n);
void Print(struct STUDENT *stud, int n);
void TotalAndAverage(struct STUDENT *stud, int n);

int main()
{
    int n;
    /***********Begin***********/
    printf("Input n(n<=30):");
    scanf("%d",&n);
                 //scanf("%d",n); 修改
    struct STUDENT a[31],*stud;
                 // stud=(struct STUDENT *)malloc(n,sizeof(struct STUDENT));
    stud=a;
    Input(stud, n); //修改
                //void Input(struct STUDENT *stud, int n);
                //stud=&a[0];
    TotalAndAverage(stud, n);//修改
                //void TotalAndAverage(struct STUDENT *stud, int n);
                //stud=&a[0];
    Print(stud, n); //修改
                //void Print(struct STUDENT *stud, int n);
    /***********End*************/
    
    return 0;
}
void Input(struct STUDENT *stud, int n)
{
    /***********Begin***********/
 
     for(int i=0;i<n;i++){
         scanf("%ld", &(*stud).num);
         scanf("%s",  (*stud).name); //&(*stud).name[13]);修改
         for(int j=0;j<4;j++){
             scanf("%f", &(*stud).score[j]);
         }
         stud++;
     }
    /***********End*************/
}
void Print(struct STUDENT *stud, int n)
{
    printf("%8s%12s%10s%10s%10s%10s%10s%10s\n","NO.","Name","Computer","English","Math","Music","Total","Average");
    for(int i=0;i<n;i++)
    {
        printf("%8ld",(*stud).num);
        printf("%12s",(*stud).name); //(*stud).name[13]); 修改
        for(int j=0;j<4;j++)
        {
            printf("%10.0f",(*stud).score[j]);
        }
        printf("%10.0f",(*stud).total);
        printf("%10.0f\n",(*stud).average);
        stud++;
    }
}
void TotalAndAverage(struct STUDENT *stud, int n)
{
    /***********Begin***********/
     float x=0;
     for(int i=0;i<n;i++){
         x=0;
         for(int j=0;j<4;j++){
             x=(*stud).score[j]+x;
         }
         (*stud).total=x;
         x=x/4.0;   //修改
         (*stud).average=x;
         stud++;
     }
    /***********End*************/
}