在结构体重输入字符数组会造成下一次输入会跳过
struct stu
{
//成员列表
//int num;
char name[20];
unsigned int age;
char tel[16];
char sex;
float score[3];
};
int main()
{
//定义结构体数组
struct stu s[2];
for (int i = 0; i < 2; i++)
{
/*printf("请输入编号:");
scanf("%d", &s[i].num);*/
printf("请输入姓名:\n");
scanf("%s", s[i].name);
printf("请输入年龄:\n");
scanf("%d", &s[i].age);
printf("请输入电话:\n");
scanf("%s", s[i].tel);
printf("请输入性别:\n");
scanf("%c", &s[i].sex);
printf("请输入分数:\n");
scanf("%f %f %f ", &s[i].score[0], &s[i].score[1], &s[i].score[2]);
}
printf("----------------------------------\n");
for (int i = 0; i < 2; i++)
{
//printf("学号:%d\n", s[i].num);
printf("姓名:%s\n", s[i].name);
printf("年龄:%d\n", s[i].age);
printf("电话:%s\n", s[i].tel);
printf("分数:%.1f %.1f %1.f\n", s[i].score[0], s[i].score[1], s[i].score[2]);
printf("性别:%s\n", s[i].sex == 'M' ? "男" : "女");
}
return 0;
|
|