随笔分类 - c
摘要:多线程实例2:#include <stdio.h> #include <stdio.h>#include <pthread.h>void thread(void) { int i; for(i=0;i<3;i++) printf("This is a pthread.\n"); }int main(void) { pthread_t id; int i,ret; ret=pthread_create(&id,NULL,(void *) thread,NULL); if(ret!=0){ printf ("Creat
阅读全文
摘要:多线程实例 :lp.c#include <pthread.h>#include <stdio.h>#include <sys/time.h>#include <string.h>#define MAX 10pthread_t thread[2];pthread_mutex_t mut;int number=0, i;void *thread1(){ printf ("thread1 : I'm thread 1\n"); for (i = 0; i < MAX; i++) { printf("threa
阅读全文
摘要:链表:#include <string.h>#include <stdlib.h>#include <stdio.h>typedef struct stu_listme stu_list;/*定义结构体*/struct stu_listme{ char* p_ch_data; stu_list* p_stu_next;};char* getform_list(stu_list* pHead, int nLim)/*取第k位数据*/ { char* p_ch_lim = NULL; int n_count = 1; stu_list* p_stu_point
阅读全文
摘要:main.c#include <stdio.h>#include <stdlib.h>#include <string.h>#include "list.h"typedef struct girl { char name[30]; int bra; int beautiful;} girl_t ;void input_girl( girl_t * girl ){ printf("Input girl name: "); gets( girl->name ); printf("Input gril bra
阅读全文
摘要:双链表 c teacher-double-nohead-noloopmain.c#include <stdio.h>#include <stdlib.h>#include <string.h>#include "list.h"typedef struct girl { char name[30]; int bra; int beautiful;} girl_t ;void input_girl( girl_t * girl ){ printf("Input girl name: "); gets( girl->n
阅读全文
摘要:c语言计算函数消耗时间:#include <sys/time.h>#include <unistd.h>struct timeval tv1, tv2; double sec =0; gettimeofday(&tv1, 0); HEGGTOPCOLLECTOR hTopCollector = eggTopCollector_new(0); // top 10 gettimeofday(&tv2, 0); sec = (double)(tv2.tv_sec - tv1.tv_sec) + (double)(tv2.tv_usec - tv1.tv_use
阅读全文
摘要:C/C++代码规范命名命名,包括文件名、类名、结构名、类型名、函数名、变量名、参数名等都是程序设计中重要的一部分。一个好的名称,体现了一个深思熟虑的过程,同时也 能够帮助别人更好地理解开发者的思路。如果发现程序中,充满了a, b, c, x, y, z, tmp这种命名的变量,这时候就需要仔细的考虑自己的实现是否有问题。类(结构)名类名必须是名词,类名必须明确表示这个类代表了什么。如果类名超过3个单词,说明这个类有可能需要拆分了。不要把父类的名字带到子类中。类名加上后缀也是一种选择。如下载代理类,可以写为DownloadProxy。类名首字母大写;用大写字母分隔单词,除单词的首字母外,全部小写
阅读全文