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

#include<stdio.h>
#include<string.h>
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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值