结构体变量赋值及成员引用

#include
#include
struct  person
{
char name[12];
int age;
char sex;
float height;
float weight;
};
int main(void)
{
struct person p1={"ZhangSan",18,'M',1.75,70.5},p2,p3;
printf("姓名 年龄 性别 身高 体重:");
scanf("%s %d %c %f %f",p2.name,&p2.age,&p2.sex,&p2.height,&p2.weight);
p3=p1;
strcpy(p3.name,"WangMing");
p3.height=1.72;
p3.weight=68;
printf("姓名 年龄 性别 身高 体重\n");
printf("%s %d %5c %10f %10f\n",p1.name,p1.age,p1.sex,p1.height,p1.weight);
printf("%s %d %5c %10f %10f\n",p2.name,p2.age,p2.sex,p2.height,p2.weight);
printf("%s %d %5c %10f %10f\n",p3.name,p3.age,p3.sex,p3.height,p3.weight);
return 0;
}

你可能感兴趣的:(结构体变量赋值及成员引用)