The C programing language chapter 6 : struct
来源:互联网 发布:mac网页视频怎么全屏 编辑:程序博客网 时间:2024/05/17 01:53
the chap6 struct
1. basics of structures
//1. define a struct way 1:struct point { int x; int y;};way 2:struct point { int x; int y;}p_test, *p_pointer;way 3:struct { int x; int y;}point; //this point just only a variale such as a from statement : int a; /*this define a struct point that is similar type int declare a struct point variable such as :*///2. declare a structstruct point p1, p2; //just like declare a normal variable except add precedence struct //3. initialize struct variable p1way 1 : p1.x = 1; p1.y = 2;way 2 : define and initializestruct point p1 = {1, 2};//4. struct of pointer,and handle it's members(x, y)struct point *p;p = &p1;p ->x = 4;p ->y = 5;
2. structures and functions
//1. return a pointer to struct point struct point makepoint(int x, int y){ struct point temp; temp.x = x; temp.y = y; return temp;}
3. arrays of structures
//declare array of struct just like char test[10];struct point pointTable[100];
4. pointers to structures
struct point *p_test; //p_test is pointer to the struct point
5. self-referential structures
//define a tree nodestruct tnode { char *value; struct tnode *left; struct tnode *right;}
6. table lookup
struct nlist { struct nlist *next; //the next pointer to the next ectry char *name;}struct nlist *nlistTab[100];//just like pointer array
7. typedef
//typedef for creating new data type names. for example ,the declarationtypedef int _int;typedef char *string;typedef struct tnode *tnode_pointer;typedef struct tnode { char *value; tnode_pointer left; tnode_pointer right;}Treenode; //creating two type : tnode_pointer and Treenode
8. unions
union { int ival; float fval; char *sval;} u;union u_tay { int ival; float fval; char *sval;};union u_tay { int ival; float fval; char *sval;} u;
9. bit-fields
struct { unsigned int is_keyword : 1; //is_keyword width is 1 that maining the it's size is 1 bit unsigned int is_extern : 1; unsigned int is_static : 1;} flags;flags.is_keyword = 1;
#ifndef STDFSH#define STDFSH 1#include "stdfs.h"#endif/*有一点我就很疑惑,对注释和字符串的处理,是保存还是忽略不管呢因为上一个getword是忽略了\/**\/ 和 “” 这个些符号之后会继续处理他们里面的内容,所以我这里就是忽略到他们里面的内容,其余的几个课后题我发现理解不了,然后去看答案,发现和题目也不是很对照啊,所以就留着以后有空在解决把,就把书上的tree的搞一个就可以了。getword : get next word or character from input*/extern int getch();extern void ungetch(int c);int getword(char *word, int lim){ int c, temp; char *w = word; while (isspace(c = getch())) ; if (c != EOF) *w++ = c; if (isalpha(c) || c == '_' || c == '#') for ( ;--lim > 0; ) { *w++ = c = getch(); if (!isalnum(c) && c != '_') { ungetch(c); break; } } else if (c == '\'' || c == '"') { for ( ;temp = getch() ; ) if (temp == c || temp == EOF) break; } else if (c == '/') { if ((temp = getch()) == '*') { for ( ;temp = getch(); ) if (temp == EOF || temp == '*' && getch() == c) break; } else ungetch(temp); } *--w = '\0'; if (temp == EOF) return EOF; return c; }int comment(){ int c; while (c=getch() != EOF) if (c == '*') if ((c = getch()) == '/') break; else ungetch(c); return c;}
0 0
- The C programing language chapter 6 : struct
- The C programing language chapter 7 : Input and Output
- The C programing language 第一章
- The C programing language K&R 笔记
- the c programing language 练习1-17
- 重读The C Programing Language的一些小纠结。
- the c programing language 1-23 删除注释
- The C programing language 第二章课后题
- The C programing language 第三章课后题
- The C programing language 第四章,课后题
- the c programing language chap5 : pointer and array
- Gotchas in the C++ programing language
- c++程序设计语言(the c++ programing language) 目录
- Day 1 :start C Language Programing course
- The C Programming Language 读书笔记(Chapter 1)
- The c programing languag chap8
- the c programing language 练习1-21 将空格字符替换为最少数量的制表符和空格
- the c programing language 1-22 较长输入行折成短些的多行,非缓冲方式实现
- 不支持默认int
- 学习笔记之深入浅出MFC 第5章 Windows程序的生与死
- 最长公共子串 | 阿里2015笔试附加题2
- Linux ping
- terminate called after throwing an instance of 'std::bad_alloc
- The C programing language chapter 6 : struct
- 欢迎使用CSDN-markdown编辑器
- 清除浮动的七种方式方法(实例代码讲解)
- BZOJ2904: 平方和
- 网页点击按钮返回顶部代码
- 【关键字private,static,final】
- iOS - UIImageView 的contentMode属性,以及图片拉伸stretchableImageWith
- Provisioning Profile的创建
- MyEclipse+Tomcat+MAVEN+SVN项目完整环境搭建