本人对嵌入式的狂爱,大学还没有毕业就来北京培训了,培训单位名叫亚嵌.来这已有4个多月了,过的很充实,很忙.因为每天学的内容太多了,消化不过来.最大的感受是对linux的提高,以前从来没有接处过这东东,到现在的系统开发,真是有点不可思意思,这过程中没有写过什么文章,只是作作笔记.以便于以后的查找.不没有共享出来给大家,因大部分都是用手抄的,以前记录了一些都在网易(http://blog.163.com/lgl_5923/blog)上的,今天把它搬过来了,发现嵌入式友线的要好一些,都是一以前做的程序,本人初学希望大家见谅!

>> 阅读全文

1. main.c file/*======================================main.c file=======================================*/#include#include"stack.h"int main(void){ push(''a''); push(''b''); push(''c''); while(!is_empty()) putchar(pop());return 0;}2.stack.c file#includestatic char stack[512];static int top = 0;/*=========== push =============*/void push(char c){ stack[top++] = c;}/*============ pop ============*/char pop(void){ return (stack[--top]);}/*========= is empty ?==========*/int is_empty(void){ return top == 0; //1 is true,so is empty}3. head file#ifndef STACK_H#define STACK_Hextern void push(char c);extern char pop(void);extern int is_empty();#endif

>> 阅读全文

1. main.c file
/*======================================main.c file=======================================*/#include#include"stack.h"int main(void){ push(''a''); push(''b''); push(''c''); while(!is_empty()) putchar(pop());return 0;}2.stack.c file#includestatic char stack[512];static int top = 0;/*=========== push =============*/void push(char c){ stack[++top] = c;}/*============ pop ============*/char pop(void){ return (stack[top--]);}/*========= is empty ?==========*/int is_empty(void){ return top == -1; //1 is true,so is empty}3. head file#ifndef STACK_H#define STACK_Hextern void push(char c);extern char pop(void);extern int is_empty();#endif

>> 阅读全文

1 #include 2 #define LEN 3 3 char buf[LEN]={''a'',''b'',''c''}; 4 void uprint(int n) 5 { 6 putchar(buf[n]); 7 if(n) // n!= 0 is true! 8 uprint(n-1); 9 }10 11 int main(void)12 {13 uprint(LEN-1);14 return 0;15 }说明:递归调用可以将整个函数调用的次数展开,看成调用别的函数,不过是函数一样,变量也是一样的。 但值得注意的是,虽然变量一样,但是它们的值是不一样的,在内存中存的位置也是不一样的,哈 我是这么理解的!栈桢: main: LEN-1 -------------------2 返回地址 uprint: n - 1 --------------------1 返回地址 n - 1 ---------------------0 返回地址

>> 阅读全文

前言: 1、对数组的排序a[]={5,3,6,2,4,7,1} 可以一次打印出1,2,3,4,5,6,7 但是这不叫算法 2、求任意一个数A的平方根,可以求一数的平方直到等于A为止,但是这也不叫算法,步数太长插入排序: 1 #include 2 /*===== insertion sort function ==========*/ 3 void insertion_sort(int a[],int len) 4 { 5 int i,j,temp; 6 for(j = 1;j 7 { 8 temp = a[j]; 9 i = j-1;10 while(i >= 0 && a[i] > temp)11 {12 a[i+1] = a[i];13 i--;14 }15 a[i+1] = temp;16 }17 for(i = 0; i 18 printf("%d",a[i]);19 }20 /*============== main function==============*/21 int main(void)22 {23 int a[] = {1,8,9,5,6,7};24 insertion_sort(a,6);25 return 0;26 }

>> 阅读全文

1. 文体文件:如果的字节骨内容范围是ASCII码可视字体的文件称这为文体文件。是一串字节,可视范围0 ~127 (0~0x7f)$: od -tx1 -tc hello_a.c 0000000 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e # i n c l u d e 0000020 68 3e 0a 20 73 74 61 74 69 63 20 66 28 69 6e 74 h > \n s t a t i c f ( i n t0000040 20 69 29 0a 7b 0a 09 69 2b 3d 31 3b 0a 09 72 65 i ) \n { \n \t i + = 1 ; \n \t r e0000060 74 75 72 6e 20 69 3b 0a 7d 0a 69 6e 74 20 6d 61 t u r n i ; \n } \n i n t m a0000100 69 6e 28 76 6f 69 64 29 0a 7b 0a 69 6e 74 20 69 i n ( v o i d ) \n { \n i n t i0000120 3d 33 3b 0a 70 72 69 6e 74 66 28 22 69 3d 25 64 = 3 ; \n p r i n t f ( " i = % d0000140 5c 6e 22 2c 66 28 69 29 29 3b 0a 72 65 74 75 72 \ n " , f ( i ) ) ; \n r e t u r0000160 6e 20 30 3b 0a 0a 7d 0a n 0 ; \n \n } \n0000170说明:0000000 0000020 0000040 0000060 等是8进制的,表示后面的字节起始位置23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e 字符ASCII(16进制)# i n c l u d e 2. 打开文件函数fopen() 创建文件: 1 #incl...

>> 阅读全文


程序标准化命令: indent file.c在程序中使用最大和最小值:INT_MAN INT_MIN 用:[d 查看值
单向链表:#include #include #include #include #define N 10typedef struct node *link;struct node { int item; link next; };link init_list();link destroy_list(link);link insertN(link, int);link removeN(link, int);void show_list(link);link NODE(int item, link next){ link t = malloc(sizeof *t); t->item = item; t->next = next; return t;}link init_list() { return NULL; }link insertN(link L, int item){ link x, y; if (!L) return NODE(item, NULL); for (y=x=L; x; y=x, x=x->next) if (item item) break; if (x==y) L = NODE(item, L); else y->next = NODE(item, x); return L;}link removeN(link L, int item){ link x, y; if (!L) return NULL; for (y=x=L; x; y=x, x=x->next) if (item == x->item) break; if (!x) return L; else if (x==y) L = L->next; else y->next = x->next; free(x); return L;}link destroy_list(link L){ link t, x; for (t=L; t; t=t->next, free(x)) x = t; r...

>> 阅读全文


关于循环链表的故事: 在罗马人占领乔塔帕特后,39个犹太人与Josephus及他的朋友躲到一个洞中,39个犹太人決定宁愿死也不要被敌人到,于是决定了一个自杀方式,41 个人排成一个圆圈,由第1个人开始报数,每报数到第3人该人就必須自杀,然后再由下一 个重新报数,直到所有人都自杀身亡为止。 然而Josephus和他的朋友並不想遵从,Josephus要他的朋友先假裝遵从,他将朋友与自己安排在第16个与第31个位置,于是逃过了这场死亡游戏。
程序实现:
#include#includetypedef struct node * link;struct node {int item; link next;};/*=============================*/link NODE (int item, link in){ link p = malloc(sizeof(*p)); p->item = item; p->next= in; return p;}
/*============================*/int main(int argc, char *argv[]){ int i; int n = atoi(argv[1]); int m = atoi(argv[2]); link t = NODE(1,NULL); t->next = t; for(i = 2; i t = t->next = NODE(i,t->next); /* t->next = NODE(i,t->next) * t = t->next; * */ while(t->next != t) // 直到只一个结点时 { for(i = 1; i t = ...

>> 阅读全文