- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
c3链表队列二叉树
?
结构和其他数据形式
关键字:struct,union,typedef
运算符:.-
/*book.c--仅包含一本书的图书目录*/
#include stdio.h
#define MAXTITL 41
#define MAXAUTL 31 struct book{//结构模板:标记为book char title[MAXTITL];
char author[MAXAUTL];
float value;
};//结构模板结束
int main(void)
{
struct book library;//把library声明为book类型的变量
printf(Please enter the book title.\n);
gets(library.title);
printf(Now enter the author.\n);
gets(library.author);
printf(Now enter the value.\n);
scanf(%f,library.value);
printf(%s by%s:$%.2f\n,library.title,library.author,library.value);
printf(%s:\%s\($%.2f)\n,library.author,library.title,library.value);
printf(Done.\n);
return 0;
}
--
结构声明(structure declaration)
struct book{
char title[MAXTITL];
char author[MAXAUTL];
float value;
};
struct book dickens;
struct book library;
--
struct{/*无标记*/
char title[MAXTITL];
char author[MAXTITL];
float value;
}library;
gets(library.title);
scanf(%f,library.value);
struct book gift={.value=25.00,
.author=James Broadfool,
.title=Rue for the Toad};
---
声明结构数组
struct book library[MAXBKS];
--
while(count MAXBKSgets(library[count].title)!=NULL
library[count].title[0]!=[message])
--
struct names{//第一个结构
char first[LEN];
char last[LEN];
};
struct guy{//第二个结构
struct names handle;//嵌套结构
char favfood[LEN];
char job[LEN];
float income;
};
printf(Hello,%s!\n,fellow.handle.first);
---
声明和初始化结构指针
struct guy*him;
him=barney;
him=fellow[0];
him-income is fellow[0].income if him==fellow[0]
fellow[0].income==(*him).income barney.income==(*him).income==him-income//him==barney
---
/*names.c--使用指向结构的指针*/
#include stdio.h
#include string.h struct namect{
char fname[20];
char lname[20];
int letters;
};
void getinfo(struct namect*);
void makeinfo(struct namect*);
void showinfo(const struct namect*);
int main(void)
{
struct namect person;
getinfo(person);
makeinfo(person);
showinfo(person);
return 0;
}
void getinfo(struct namect*pst)
{
printf(Please enter your first name.\n);
gets(pst-fname);
printf(Please enter you last name.\n);
gets(pst-lname);
}
void makeinfo(stru
您可能关注的文档
最近下载
- 草果栽培技术.ppt VIP
- 药物设计软件:Schrodinger二次开发_(16).Schrodinger插件开发与使用.docx VIP
- 浙江省9+1高中联盟2024-2025学年高二上学期11月期中考试物理试题(含答案).docx VIP
- 教育研究导论(宁虹主编)笔记.pdf VIP
- 药物设计软件:Schrodinger二次开发_(15).自定义分子力场与参数化.docx VIP
- 2019年高铁动车广告,高铁车身广告,高铁广告价格.pdf VIP
- 高考数学考点题型全归纳.pdf VIP
- 万华化学安全管理实践.pdf VIP
- 丹纳赫DBS管理系统.pptx VIP
- 金属焊接软件:SYSWELD二次开发_(6).焊接热源模型开发.docx VIP
文档评论(0)