关于C语言结构体的编译问题


#include
    struct student{
        char num[10];
        char name[10];
        float score[3];
    };
 
 int main()
 {
     int n;
     scanf("%d",&n);
     void input(struct student stu[],int n);
 
     void print(struct student stu,int n);
     struct student stu[n],*p=stu;
     input(p,n);
     print(p,n);
     return 0;
 }
 
 void input(struct student stu[],int n)
 {
     int i;
     for(i=0;iscanf("%c %c %f %f %f",&stu[i].num,&stu[i].name,&stu[i].score[0],
                             &stu[i].score[1],&stu[i].score[2]);
     }
     
 }
 
 void print(struct student stu[],int n)
 {
     int i;
     for(i=0;iprintf("%c,%c,%f,%f,%f\n",stu[i].num,stu[i].name,stu[i].score[0],
         stu[i].score[1],stu[i].score[2]);
 }
 }

img

想知道问题出在哪,怎么改呀?

 
#include<stdio.h>
    struct student{
        char num[10];
        char name[10];
        float score[3];
    };
 
void input(student stu[],int n);
 
void print(student stu[],int n);

 int main()
 {
     int n;
     scanf("%d",&n);

     student stu[n],*p;
     p=stu;
     input(p,n);
     print(p,n);
     return 0;
 }
 
 void input(student stu[],int n)
 {
     int i;
     for(i=0;i<n;i++)
     {
         scanf("%s %s %f %f %f",&stu[i].num,&stu[i].name,&stu[i].score[0],
                             &stu[i].score[1],&stu[i].score[2]);
     }
     
 }
 
 void print(student stu[],int n)
 {
     int i;
     for(i=0;i<n;i++)
     {
         printf("%c,%c,%f,%f,%f\n",stu[i].num,stu[i].name,stu[i].score[0],
         stu[i].score[1],stu[i].score[2]);
 }


提供的程序问题比较多,已经对此修改如下,还添加了相应的打印信息。如有问题可私信。

#include<stdio.h>
struct student{
    char num[10];
    char name[10];
    float score[3];
};
 void input(struct student *stu,int n);
 void print(struct student *stu,int n);
 int main()
 {
     int n;
     printf("please input n\n");
     scanf("%d",&n);
     
     struct student stu[n],*p=stu;
     input(p,n);
     print(p,n);
     return 0;
 }
 
 void input(struct student *stu,int n)
 {
     int i;
     for(i=0;i<n;i++)
     {
        printf("please input num,name,score0 score1 score2\n");
         scanf("%s %s %f %f %f",&stu[i].num,&stu[i].name,&stu[i].score[0],
                             &stu[i].score[1],&stu[i].score[2]);
     }
     
 }
 
 void print(struct student *stu,int n)
 {
    int i;
    for(i=0;i<n;i++)
    {
         printf("%s,%s,%f,%f,%f\n",stu[i].num,stu[i].name,stu[i].score[0],
         stu[i].score[1],stu[i].score[2]);
    }
 }

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^