为什么它输出的和我想的不一样,还要再多输入一行数字?

定义一个 struct student 类型的结构指针,在主函数中用结构指针实现一个学生信息的输入和输出。

输入:668899 Ken 80 90 99
输出:668899 Ken 80 90 99

img

img



struct Student
{
   int id;
   char name[20];
   int score[3];
};

int main()
{
   struct Student *s;
   s = (struct Student *)malloc(sizeof(struct Student));
   scanf("%d%s", &s->id, s->name);
   for (int i = 0; i < 3; i++)
      scanf("%d", &s->score[i]);

   printf("%d %s", s->id, s->name);
   for (int i = 0; i < 3; i++)
      printf(" %d", s->score[i]);
   return 0;
}

一次循环进行3次输入,循环两次就是6次输入了吖

你写的相当于有两个学生,第一个学号是668899,名字是Ken,成绩是80。第二个学生学号是90,名字是99,成绩是1