收藏 分享(赏)

C程序设计9-结构与链表.ppt

上传人:j35w19 文档编号:8114946 上传时间:2019-06-09 格式:PPT 页数:9 大小:76.50KB
下载 相关 举报
C程序设计9-结构与链表.ppt_第1页
第1页 / 共9页
C程序设计9-结构与链表.ppt_第2页
第2页 / 共9页
C程序设计9-结构与链表.ppt_第3页
第3页 / 共9页
C程序设计9-结构与链表.ppt_第4页
第4页 / 共9页
C程序设计9-结构与链表.ppt_第5页
第5页 / 共9页
点击查看更多>>
资源描述

1、1,第九章 结构与链表,9.1 结构的概念与定义方法 将不同类型的分量(数据项)组合形成新的类型,这种类型被称之为结构. Struct student Int num; Char name16; Char sex; Int age; Float score; Char address36 ;,Typedef struct student STUDENT;,练习:一个学校(单位)的信息,一台电脑的信息,具有多门课程的同学信息,2,第九章 结构与链表,9.2 结构的使用 Struct student Int num; Char name16; Char sex; Int age; Float sc

2、ore; Char address36 ;,Main() Struct student myStudent; myStudent.num = 100; myStudent.sex = M;Struct student yourStudent; yourStudent.num = 101; ,示例,3,第九章 结构与链表,9.3 结构体的初始化 Struct student Int num; Char name16; Char sex; Int age; Float score; Char address36 ;,Main() Struct student myStudent=1, “Mr. G

3、ao”, M, 44, 90.2,”abc”; Printf(“%d, %s, %c, %d, %f, %s”, myStudent.num, .); ,示例,4,第九章 结构与链表,9.4 结构体数组 Struct student Int num; Char name16; Char sex; Int age; Float score; Char address36 ;,Main() Struct student myStudent100; myStudent0.num = 100; myStudent0.sex = M;Printf(“%d,%d”, myStudent0. myStude

4、nt0. num); 例如:求100个学生的平均年令.,5,第九章 结构与链表,9.5 结构体指针 Struct student Int num; Char name16; Char sex; Int age; Float score; Char address36 ;,Main() Struct student *p; P = malloc(sizeof(struct student); (*p).num = 100; P-sex = m; ,拓展:结构体组成的数组与指针的关系,6,第九章 结构与链表,9.6结构体变量作为函数参数 (1)用结构体变量的成员作为函数参数:讨论 (2)结构变量作

5、为函数参数 (3)结构变量的指针作为函数参数,Struct student Int num; Char name16; Char sex; Int age; Float score; Char address36 ;,Main() Struct student p; p.num = 100; P.sex = m; F(p); Void f(struct student x) x.Num = x.num + 1; ,示例,7,第九章 结构与链表,9.7链表 (1)概念:链表是通过指针将结构变量链接在一起形成的一种存贮数据的数据结构 (2)与数组的异同:(1)都是存贮一组数据(2)数组是连接存贮空

6、间,链接非连接(3)尺寸 (3)链表的组织结构,Struct student Int num; Char name16; Char sex; Int age; Float score; Char address36 Struct student *next; ;,示例,head,8,第九章 结构与链表,9.7链表 (4)链表建立,插入结点,删除结点,访问结点,链表的释放,Struct student Int num; Char name16; Char sex; Int age; Float score; Char address36 Struct student *next; ;,示例,head,9,第十章 文件,10.1文件 (1)文件的概念 (2)FILE类型 (3)文件的访问 FILE * fopen(文件名, 读写标志) Fprintf(文件指针,格式控制串,表达式组组成的输出列表) Fscanf(文件指针,格式控制串,地址组成的输入列表 Fclose(文件指针) feof(fp) (4)其他文件访问函数 Fputc(),fgetc(),fread(), fwrite(),fgets(),fputs() (5)文件的定位: Rewind(),fseek(),ftell() (6)出错检测:ferror(fp), clearerr(fp),feof(fp),示例,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报