为什么输入数据的时候程序自动显示出来完了呢?
程序代码:
# include<stdio.h>
# include<windows.h>
# include<malloc.h>
struct stu
{
char name;
char sex;
int age;
int score;
};
void input(struct stu * p, int len)
{
for (int i = 0; i < len; ++i)
{
printf("输入%d组数据:", i + 1);
printf("\n输入姓名:");
printf("\n输入性别:");
printf("\n输入年龄:");
printf("\n输入分数:\n");
scanf("%c %c %d %d", &p[i].name, &p[i].sex, &p[i].age, &p[i].score);
};
};
void output(struct stu * q, char * r)
{
printf(" 姓名:%c\n", q[*r].name);
printf(" 性别:%c\n", q[*r].sex);
printf(" 年龄:%d\n", q[*r].age);
printf(" 分数:%d\n", q[*r].score);
}
int main(void)
{
int len; /*此为数据个数*/
printf("\n输入即将录入的数据个数:");
scanf("%d", &len);
struct stu * student = (struct stu *)malloc(sizeof(struct stu) * len); /*定义x为动态数组*/
input(student, len); /*此为输入通道*/
printf("\n输入你想要的第几组数据:");
char y; /*此为输出通道*/
scanf("%c", &y);
output(student, &y);
system("pause");
return 0;
}第一次输入的时候程序还停了一下,第二次输入的时候程序就把下面的文字全都输出了,没法输入数据啊。大神来救。









