qfedu-c-level/day12/d12.c

26 lines
767 B
C
Raw Normal View History

#include <stdio.h>
#include <string.h>
typedef struct stu_s
{
unsigned short sid;
// char name[32] = ""; // 不能在定义时初始化,因为结构体是类型,不是变量
char name[32];
unsigned short hight;
float weight;
} STU_INFO;
int main()
{
for (int i = 0; i < 3; i++)
{
// struct stu_s stu; // 重复定义,不会报错,但是不建议这么做
STU_INFO stu;
printf("请输入学号 姓名 身高 体重:");
// %hu 是 unsigned short 的格式化输出
scanf("%hu %s %hu %f", &stu.sid, stu.name, &stu.hight, &stu.weight);
printf("第%d位-->学号:%hu 姓名:%s 身高:%hu 体重:%.2f\n", i + 1, stu.sid, stu.name, stu.hight, stu.weight);
}
return 0;
}