[C程序设计基础及实验]Lect_chap09_结构.pdfVIP

  • 0
  • 0
  • 约1.19万字
  • 约 38页
  • 2017-06-24 发布于湖北
  • 举报

[C程序设计基础及实验]Lect_chap09_结构.pdf

Chap 9 结构 9.1 构建手机通讯录 9.2 结构变量 9.3 结构数组 9.4 结构指针 本章要点  什么是结构?结构与数组有什么差别?  有几种结构的定义形式,它们之间有什么不同?  什么是结构的嵌套?  什么是结构变量和结构成员变量,如何引用结构 成员变量?  结构变量如何作为函数参数使用?  什么是结构数组,如何定义和使用结构数组?  什么是结构指针,它如何实现对结构分量的操作?  结构指针是如何作为函数的参数的? 9.1 构建手机通讯录 9.1.1 程序解析 9.1.2 结构的概念与定义 9.1.3 结构的嵌套定义 9.1.1 程序解析 例9-1 构建简单的手机通讯录 联系人的基本信息:姓名、年龄和联系电话 最多容纳50名联系人的信息 具有新建和查询功能 程序解析-源程序 #includestdio.h #includestring.h /*手机通讯录结构定义*/ struct friends_list{ char name[10]; /* 姓名*/ int age; /* 年龄*/ char telephone[13]; /* 联系电话*/ }; int Count = 0; /* 全局变量记录当前联系人总数*/ void new_friend(struct friends_list friends[ ] ); void search_friend(struct friends_list friends[ ], char *name); int main(void) 源程序 { int choice; char name[10]; struct friends_list friends[50]; /* 包含50个人的通讯录*/ do{ printf(手机通讯录功能选项:1:新建2:查询0:退出\n); printf(请选择功能:); scanf(%d, choice); switch(choice){ case 1: new_friend(friends); break; case 2: printf(请输入要查找的联系人名:); scanf(%s, name); search_friend(friends, name); break; case 0: break; } }while(choice != 0); printf(谢谢使用通讯录功能!\n); return 0; } /*新建联系人*/ 源程序 void new_friend(struct friends_list friends[ ]) { struct friends_list f; if(Count == 50){ printf(通讯录已满!\n); return; } printf(请输入新联系人的姓名:); scanf(%s, f.name); printf(请输入新联系人的年龄:); scanf(%d, f.age); printf(请输入新联系人的联系电话:); scanf(%s, f.telephone); friends[Count] = f; Count++; } /*查询联系人*/ void search_friend(struct friends_list friends[ ], char

文档评论(0)

1亿VIP精品文档

相关文档