数据结构指针

# include <stdio.h>

/*

生命结构体定义:

1.struct 结构体名称

{结构体成员;}数组名【长度】 ;

2.struct 结构体名称

{结构体成员;};

struct 结构体名称 数组名【长度】; */

/*结构体指针

struct Book *p;

p=&book //别忘了&

(*结构体指针).成员名//对象.成员名 //.的优先级更高

结构体指针->成员 //对象指针—>成员名 */

int main()

{

struct Date

{

int year;

int month;

int day;

};

struct Book

{

char title[128];

char auchor[40];

float price ;

struct Date date;

char publicer[40];

} book;

struct Book *pt; //结构体指针

pt=&book;

printf("请出入书名:");

scanf("%s",(*pt).title);

printf("请输入作者:");

scanf("%s",(*pt).auchor);

printf("请输入售价:");

scanf("%f",&(*pt).price);

printf("情输入出版日期:");

scanf("%d-%d-%d",&(*pt).date.year,&(*pt).date.month,&(*pt).date.day);

printf("请输入出版社:") ;

scanf("%s",(*pt).publicer);

printf("\n=========数据录入完毕============");

printf("书名:%s\n",(*pt).title);//所有的(*p.)可以替换成pt->

printf("作者:%s\n",(*pt).auchor);

printf("售价:%.2f\n",(*pt).price);

printf("出版日期:%d-%d-%d\n",(*pt).date.year,(*pt).date.month,(*pt).date.day);

printf("请输入出版社:%s\n",(*pt).publicer);

//printf("size of book=%d",sizeof(book));

return 0;

}/*初始化:

struct Book book={

.publicer="清华";

.price =48.8;

.date=2022102;}; */

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值