随笔分类 -  c

摘要:使用gcc的警告信息间接知道变量的类型#include #include #include #include intmain(){ int a[2][10]; printf("%d\n", a[0]); printf("%d\n", a); p... 阅读全文
posted @ 2014-11-22 11:19 lxgeek 阅读(2320) 评论(0) 推荐(2)
摘要:#include <locale.h>#include <stdlib.h>#include <stdio.h>intmain( void ){ printf( "%s\n", setlocale( LC_ALL, "" ) ); exit(0);} 阅读全文
posted @ 2012-03-11 20:41 lxgeek 阅读(203) 评论(0) 推荐(0)
摘要:in_cksum(addr, len)u_short *addr;int len;{ register int nleft = len; register u_short *w = addr; register u_short answer; register int sum = 0; /* * Our algorithm is simple, using a 32 bit accumulator (sum), * we add sequential 16 bit words to it,... 阅读全文
posted @ 2012-01-05 15:23 lxgeek 阅读(642) 评论(0) 推荐(0)
摘要:#include <stdio.h>#include <stdlib.h>typedef unsigned char *byte_pointer;void show_bytes( byte_pointer start, int len ){ int i; for ( i = 0; i < len; i++ ) { printf( "%.2x", start[i] ); } printf( "\n" );}void show_int( int x ){ show_bytes( (by... 阅读全文
posted @ 2011-12-21 17:01 lxgeek 阅读(558) 评论(0) 推荐(0)
摘要:#include <stdlib.h>#include <stdio.h>intmain( int argc, char** argv ){ int i = 0; for ( ; i < argc; i++ ) { printf( "argv[%d] is %s\n", i, argv[i] ); } int arg_c = argc; char** arg_v = argv; arg_c--, arg_v++; while (arg_c > 0 && ... 阅读全文
posted @ 2011-12-12 21:18 lxgeek 阅读(249) 评论(0) 推荐(0)
摘要:#include <stdio.h>#include <stdlib.h>voidhello( a, b )int a ;int b ;{ a = 5; b = 6; printf( "a is %d \n b is %d\n", a, b );}intmain(){ hello(); exit( 0 );} 阅读全文
posted @ 2011-10-26 19:17 lxgeek 阅读(232) 评论(0) 推荐(0)
摘要:/* * author:lx * date: 2011-10-04 * brief: strcpy */#include <stdio.h>#include <stdlib.h>#include <assert.h>void*lx_strcpy( char *p, char *q ){ char *address = q; for ( ; *p != '\0'; p++ ) { assert( *q != '\0' ); *q = *p; ... 阅读全文
posted @ 2011-10-04 14:50 lxgeek 阅读(226) 评论(0) 推荐(0)
摘要:/* * author:lx * date:2011-10-04 * brief: convent int to string */#include <stdio.h>#include <stdlib.h>voidcon_string( int a ){ int m = 10; char p[6]; int c = 1; char *q = p; while ( a != 0 ) { c = a % m; a = a / ... 阅读全文
posted @ 2011-10-04 14:34 lxgeek 阅读(203) 评论(0) 推荐(0)
摘要:/* * author:lx * breif: 2011.09.22 * brief: quick-sort */#include <stdio.h>#include <stdlib.h>voidquick_sort( int *x, int l, int u ){ if ( l >= u ) { return; } int m = l; int i; for ( i = l+1; i < u; i++ ) { if ( x[i] < x... 阅读全文
posted @ 2011-09-22 19:25 lxgeek 阅读(130) 评论(0) 推荐(0)
摘要:/* * author:lx * date:2011.09.22 * brief: insertion-sort */#include <stdio.h>#include <stdlib.h>void insertion_sort( int *p, int len ){ int j = 1; int key = 0; int i; for ( ; j < len; j++ ) { key = p[j]; i = j - 1; while... 阅读全文
posted @ 2011-09-22 16:17 lxgeek 阅读(142) 评论(0) 推荐(0)
摘要:/* * brief: genericity programming * */#include <stdio.h>#include <stdlib.h>#include <assert.h>#define GENERIC_STACK( STACK_TYPE, SUFFIX, STACK_SIZE ) \ \ static STACK_TYPE stack##SUFFIX[ STACK_SIZE ]; \ st... 阅读全文
posted @ 2011-09-17 15:56 lxgeek 阅读(172) 评论(0) 推荐(0)
摘要:/* * author: lx * date: 2011-09-16 * brief: programming pearls column2 */#include <stdio.h>#include <stdlib.h>voidmove_vector( char* b, int m, int n ){ int i = 0; int j; char temp; for ( ; i < n ; i++ ) { for ( j = i; j < m; j += n ) {... 阅读全文
posted @ 2011-09-17 13:23 lxgeek 阅读(181) 评论(0) 推荐(0)
摘要:#include <stdio.h>#include <stdlib.h>typedef unsigned char *byte_pointer;voidshow_bytes( byte_pointer start, int len ){ int i; for ( i = 0; i < len; i++ ) printf( " %.2x", start[i] ); printf( "\n" );}voidshow_int( int x ){ show_bytes( ( byte_pointer )&x, si... 阅读全文
posted @ 2011-09-15 19:13 lxgeek 阅读(202) 评论(0) 推荐(0)
摘要:/* * author: lx * date: 2011-09-08 * brief: the interface of list * file: llist.c */#include <stdio.h>#include <stdlib.h>#include "llist.h"intinsert_list( register Node **linkp, int new_value ){ register Node *current; register Node *new; while ( ( current = *linkp ) != NULL &a 阅读全文
posted @ 2011-09-15 16:27 lxgeek 阅读(160) 评论(0) 推荐(0)
摘要:#include <stdio.h>#include <stdlib.h>#include <malloc.h>#include <assert.h>#include <pthread.h>#define FALSE 0pthread_mutex_t thread_mutex = PTHREAD_MUTEX_INITIALIZER;pthread_mutex_t task_mutex = PTHREAD_MUTEX_INITIALIZER;struct temp{ int name;};#define STACK_TYPE struc 阅读全文
posted @ 2011-08-10 14:08 lxgeek 阅读(366) 评论(0) 推荐(0)
摘要:/** author: lx date 4.11 2011 biref BN*/#pragma once#include <string>#include <map>#include <vector>#include <iostream>using namespace std;typedef pair< char, float > inter;/* struct of node */struct nbnode{ char name[20]; /* name */ vector< inter > nodeprob; /* p 阅读全文
posted @ 2011-04-11 19:38 lxgeek 阅读(413) 评论(0) 推荐(0)
摘要:#pragma once#include<list>using namespace std;class roundrobin//class representing round robin scheduling{ int *rq;//request times int n;//number of processes int q;//time quantum int *w;//wait times int *t;//turn-around times int *a;//arrival times list<int> order;public: roundrobin(voi 阅读全文
posted @ 2011-04-10 14:24 lxgeek 阅读(2640) 评论(0) 推荐(1)
摘要:/** auhtor:lx date 4.9 2011 brief hash table*/#include <stdio.h>#include <stdlib.h>#include <stdbool.h>#define hash_num 5typedef char Bool;struct hash_node{ int date; /*结点值*/ struct hash_node *next; /*下一个节点*/ Bool found;};struct hash_node* hash_table[hash_num]; /*存储hash table 所有信息* 阅读全文
posted @ 2011-04-09 16:12 lxgeek 阅读(350) 评论(0) 推荐(0)
摘要:#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include "ourhdr.h"#include "error.c"#include "f10.17.c"static void lockabyte(const char *, int, off_t );int lock_reg( int fd, int cmd, int type, off_t offset, int whence, off_t len ){ struct 阅读全文
posted @ 2011-04-04 20:14 lxgeek 阅读(205) 评论(0) 推荐(0)
摘要:/** author lx date 3.24 2011 contact lxlenovostar@gmail.com biref cp a big file to anthor file.*/#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <stdlib.h>#include <unistd.h>#include <stdio.h>#include <errno.h>#include <string.h># 阅读全文
posted @ 2011-03-24 18:42 lxgeek 阅读(725) 评论(0) 推荐(0)

点击右上角即可分享
微信分享提示