user-0 提问: 刚自学的C语言 自己编了个程序,可是很多错误,求解释...

回复:
user: user-1
content: #include<stdlib.h> #include<stdio.h> #include <string.h>  struct student_st {     int num;     char name[20];     int score1;     int score2;     int score3;     float average; };  void CopyStudent(student_st &dst, const student_st &src) {     dst = src;     strcpy(dst.name, src.name); }  void createstudent(struct student_st *stu) {     int i, j;     float average;     for (i = 0; i < 3; i++)     {         printf("enter student %d\n", i + 1);         printf("学号为:");         scanf("%d", &stu[i].num);         printf("姓名是:");         scanf("%s", stu[i].name);         printf("第1门成绩是:");         scanf("%d", &stu[i].score1);         printf("第2门成绩是:");         scanf("%d", &stu[i].score2);         printf("第3门成绩是:");         scanf("%d", &stu[i].score3);         printf("\n");         stu[i].average = (stu[i].score1 + stu[i].score2 + stu[i].score3) / 3.0f;     } }  void sortstudent(struct student_st *stu, int c)  {     int i, j, max;     struct student_st temp;     for (i = 0; i < c; i++)     {         max = i;         for (j = i + 1; j < c; j++)         {             if (stu[j].average > stu[max].average)                 max = j;         }         if (max != i)         {             CopyStudent(temp, stu[max]);             CopyStudent(stu[max], stu[i]);             CopyStudent(stu[i], temp);         }     } }  int main() {     int i;     struct student_st stu[3];     createstudent(stu);     sortstudent(stu, 3);     printf("id\tname\tscore1\tscore2\tscore3\taverage\n");     for (i = 0; i < 3; i++)     {         printf("%d %s %d %d %d %0.1f", stu[i].num, stu[i].name, stu[i].score1, stu[i].score2, stu[i].score3, stu[i].average);         printf("\n");     } }

user: user-0
content: 引用 2 楼 幻夢之葉的回复: #include<stdlib.h> #include<stdio.h> #include <string.h>  struct student_st {     int num;     char name[20];     int score1;     int score2;     int score3;     float average; };  void CopyStudent(student_st &dst, const student_st &src) {     dst = src;     strcpy(dst.name, src.name); }  void createstudent(struct student_st *stu) {     int i, j;     float average;     for (i = 0; i < 3; i++)     {         printf("enter student %d\n", i + 1);         printf("学号为:");         scanf("%d", &stu[i].num);         printf("姓名是:");         scanf("%s", stu[i].name);         printf("第1门成绩是:");         scanf("%d", &stu[i].score1);         printf("第2门成绩是:");         scanf("%d", &stu[i].score2);         printf("第3门成绩是:");         scanf("%d", &stu[i].score3);         printf("\n");         stu[i].average = (stu[i].score1 + stu[i].score2 + stu[i].score3) / 3.0f;     } }  void sortstudent(struct student_st *stu, int c)  {     int i, j, max;     struct student_st temp;     for (i = 0; i < c; i++)     {         max = i;         for (j = i + 1; j < c; j++)         {             if (stu[j].average > stu[max].average)                 max = j;         }         if (max != i)         {             CopyStudent(temp, stu[max]);             CopyStudent(stu[max], stu[i]);             CopyStudent(stu[i], temp);         }     } }  int main() {     int i;     struct student_st stu[3];     createstudent(stu);     sortstudent(stu, 3);     printf("id\tname\tscore1\tscore2\tscore3\taverage\n");     for (i = 0; i < 3; i++)     {         printf("%d %s %d %d %d %0.1f", stu[i].num, stu[i].name, stu[i].score1, stu[i].score2, stu[i].score3, stu[i].average);         printf("\n");     } }  膜拜  大神  回去好好看看

user: user-0
content: 引用 3 楼 小灸舞的回复:1.形参名应该是stu，类型应该是struct student_st *stu 2.主函数里struct student_st stu;struct student_st stu[3];2个都叫stu? 3.createstudent函数里score1都写成了Score1 PS：自己根据编译器错误改改并不是很难 OK  谢谢 大神 唉 英语比较烂 看不怎么懂

user: user-2
content: 1.形参名应该是stu，类型应该是struct student_st *stu 2.主函数里struct student_st stu;struct student_st stu[3];2个都叫stu? 3.createstudent函数里score1都写成了Score1 PS：自己根据编译器错误改改并不是很难

user: user-3
content: 主函数中的stu是个局部变量，仅在主函数中可用，其他函数中的stu是没有定义过的