文章分类 -  C代码

1 2 下一页
stdarg.h
摘要:原文:http://baike.baidu.com/view/3373010.htmstdarg.h stdarg.h是C语言中C标准函式库的标头档,stdarg是由standard(标准) arguments(参数)简化而来,主要目的为让函式能够接收不定量参数。[1] C++的cstdarg标头档中也提供这样的机能;虽然与C的标头档是相容的,但是也有冲突存在。 不定参数函式(Variadic functions)是stdarg.h内容典型的应用,虽然也可以使用在其他由不定参数函式呼叫的函式(例如,vprintf)。 宣告不定参数函式 不定参数函式的参数数量是可变动的,它使用省略号来忽... 阅读全文
posted @ 2011-12-05 10:00 hotty 阅读(579) 评论(0) 推荐(0)
C语言数据类型
摘要:原文:http://zhidao.baidu.com/question/116383335.html?an=0&si=1C语言各种数据类型及其在系统中占的字节和取值范围2009-08-21 09:53C语言包含5个基本数据类型: void, int, float, double, 和 char. (另:C++ 定义了另外两个基本数据类型: bool 和 wchar_t. 一些基本数据类型能够被 signed, unsigned, short, 和 long 修饰所以short,long等等都不算基本数据类型。这是书上说的,所以C++是7种基本数据类型。空值型是一种,但枚举型不算。原因就 阅读全文
posted @ 2011-12-01 10:29 hotty 阅读(2944) 评论(0) 推荐(0)
栈的应用--行编辑器
摘要:View Code #include <stdio.h>#include <stdlib.h>#define STACK_INIT_SIZE 10#define STACKINCREMENT 2typedef int SElemType;struct SqStack{ SElemType *base; SElemType *top; int stacksize;};#define SqStack struct SqStackint InitStack(SqStack *S){ if ( !(S->base = (SElemType *) malloc (STAC. 阅读全文
posted @ 2011-11-28 10:45 hotty 阅读(230) 评论(0) 推荐(0)
栈的应用--左右括号匹配
摘要:注意gets这个函数不建议使用,用的时候会出现告警;第一个code的e类型为int行,主要是因为无论是“(”或是“[”都可以转换为ascll码,第二个code为字符型View Code #include <stdio.h>#include <stdlib.h>#define STACK_INIT_SIZE 10#define STACKINCREMENT 2typedef int SElemType;struct SqStack{ SElemType *base; SElemType *top; int stacksize;};#define SqStack struc 阅读全文
posted @ 2011-11-25 11:20 hotty 阅读(273) 评论(0) 推荐(0)
栈的应用--数值转换-10转换成16
摘要:View Code #include <stdio.h>#include <stdlib.h>#define STACK_INIT_SIZE 10#define STACKINCREMENT 2typedef int SElemType;struct SqStack{ SElemType *base; SElemType *top; int stacksize;};#define SqStack struct SqStackint InitStack(SqStack *S){ if ( !(S->base = (SElemType *) malloc (STAC. 阅读全文
posted @ 2011-11-25 10:37 hotty 阅读(225) 评论(0) 推荐(0)
栈的应用--数值转换-10转换成8
摘要:View Code #include <stdio.h>#include <stdlib.h>#define STACK_INIT_SIZE 10#define STACKINCREMENT 2typedef int SElemType;struct SqStack{ SElemType *base; SElemType *top; int stacksize;};#define SqStack struct SqStackint InitStack(SqStack *S){ if ( !(S->base = (SElemType *) malloc (STAC. 阅读全文
posted @ 2011-11-25 10:26 hotty 阅读(213) 评论(0) 推荐(0)
3.0 栈-1
摘要:View Code #include <stdio.h>#include <stdlib.h>#define STACK_INIT_SIZE 10#define STACKINCREMENT 2typedef int SElemType;struct SqStack{ SElemType *base; SElemType *top; int stacksize;};#define SqStack struct SqStackint InitStack(SqStack *S){ if ( !(S->base = (SElemType *) malloc (STAC. 阅读全文
posted @ 2011-11-24 16:26 hotty 阅读(104) 评论(0) 推荐(0)
3.0 栈
摘要:编辑器加载中.. 1 #include <stdio.h> 2 #include <stdlib.h> 3 4 #define STACK_INIT_SIZE 10 5 #define STACKINCREMENT 2 6 7 typedef int SElemType; 8 9 struct SqStack{ 10 SElemType *base; 11 SElemType *top; 12 int stacksize; 13 }; 14 15 #define SqStack struct SqStack 16 17 int InitSta... 阅读全文
posted @ 2011-11-24 16:25 hotty 阅读(149) 评论(0) 推荐(0)
C实现遍历文件夹及删除其内容
摘要:原文:apps.hi.baidu.com/share/detail/32164843转自:http://zhougaofeng.ixiezi.com/2011/03/29/rm_dir/好久没更新博客,最近写了一段文件夹遍历的代码,实现删除文件夹下所有文件的功能贴上来供大家参考#include <dirent.h> #include <stdio.h> #include <string.h>void rm_dir(char *path);void usage();int main(int argv, char *argc[]) { if(argv != 2) 阅读全文
posted @ 2011-10-11 11:02 hotty 阅读(601) 评论(1) 推荐(1)
va_start(ap,fmt);这段代码什么意思?
摘要:原文:http://zhidao.baidu.com/question/255040285.html问:va_start(ap,fmt); vsprintf(buff,fmt,ap); va_end(ap);这段代码什么意思?答:你要是对这个问题,有问题,那你应该不清楚 c 可以处理,变长的参数了吧?、c 的 printf 的函数原型,你清楚不?int printf(const char *fmt, ...); // 逗号,后面,即第二个参数是三个点vsprintf 的函数原型:int vsprintf(char *s, const char *fmt, va_list arg);你见过... 阅读全文
posted @ 2011-09-21 09:57 hotty 阅读(1521) 评论(1) 推荐(1)
按位与运算符(&)
摘要:原文:http://blog.sina.com.cn/s/blog_45e9348c010006uj.html参加运算的两个数据,按二进位进行“与”运算。如果两个相应的二进位都为1,则该位的结果值为1,否则为0。即 0&0=0;0&1=0;1&0=0;1&1=1;例如: 3&5 并不等于8,应该是按位与。3 = 00000011(&) 5= 0000010100000001因此,3&5的值得1。如果参加&是负数运算的是负数(如-3 & -5),则以补码形式表示为二进制数,然后按位进行“与”运算。按位与有一些特殊的用途:(1 阅读全文
posted @ 2011-09-20 14:54 hotty 阅读(510) 评论(0) 推荐(0)
C语言整形转换成字符型然后赋值到字符数组
摘要:原文:http://zhidao.baidu.com/question/165294435.htmlsprintf(str, "%d ", iNumber); //把数字转换为字符串了具体实现:#include<stdio.h>void main(){ int a=120; char b[4]; sprintf(b, "%d ", a); printf("%s\n",b);} 阅读全文
posted @ 2011-06-30 22:49 hotty 阅读(891) 评论(0) 推荐(0)
哈希排序C
摘要:#include<stdio.h>#include<malloc.h>#define NULLKEY 0#define N 10typedef int KeyType;typedef struct{ KeyType key; int ord;}ElemType;int hashsize[]={11,19,29,37};int m=0;typedef struct{ ElemType *elem; int count; int sizeindex;}HashTable;#define SUCCESS 1#define UNSUCCESS 0#define DUPLICAT 阅读全文
posted @ 2011-06-30 15:44 hotty 阅读(679) 评论(0) 推荐(0)
哈希表
摘要:原文:http://wenku.baidu.com/view/52208b10cc7931b765ce155f.html/* 数据结构C语言版 哈希表 P259 编译环境:Dev-C++ 4.9.9.2 日期:2011年2月15日 */#include <stdio.h>#include <malloc.h>#define NULLKEY 0 // 0为无记录标志 #define N 10 // 数据元素个数 typedef int KeyType;// 设关键字域为整型 typedef struct{ KeyType key; int ord;}ElemType; / 阅读全文
posted @ 2011-06-30 10:14 hotty 阅读(631) 评论(0) 推荐(0)
动态数据链表
摘要:#define NULL 0#define TYPE struct stu#define LEN sizeof(struct stu)struct stu{ int num; int age; struct stu *next;};TYPE * creat(int n){ struct stu *head,*pf,*pb; int i; for(i=0;i<n;i++) { pb=(TYPE*)malloc(LEN); printf("input Number and Age\n"); scanf("%d%d",&pb->num,&a 阅读全文
posted @ 2011-06-29 18:04 hotty 阅读(185) 评论(0) 推荐(0)
哈希排序 c表示
摘要:原文:http://zhidao.baidu.com/question/274686944.html#include<stdlib.h>#include<stdio.h>#define NULL 0typedef int KeyType;typedef struct{ KeyType key;} ElemType;int haxi(KeyType key,int m) /*根据哈希表长m,构造除留余数法的哈希函数haxi*/{ int i,p,flag; for(p=m;p>=2;p--) /*p为不超过m的最大素数*/ { for(i=2,flag=1;i< 阅读全文
posted @ 2011-06-29 18:03 hotty 阅读(1309) 评论(0) 推荐(1)
Linux程序设计——用getopt处理命令行参数
摘要:原文:http://blogold.chinaunix.net/u/7040/showart_244389.htmlLinux下很多程序甚至那些具有图形用户界面(graphical user interface,GUI)的程序,都能接受和处理命令行选项。对于某些程序,这是与用户进行交互的主要手段。具有可靠的复杂命令行参数处理机制,会使得您的应用程序更好、更有用。getopt()是一个专门设计来减轻命令行处理负担的库函数。1、命令行参数命令行程序设计的首要任务是解析命令行参数,GUI派的程序员很少关心这个。这里,对参数采用了一种比较通俗的定义:命令行上除命令名之外的字符串。参数由多项构成,项与项 阅读全文
posted @ 2011-06-27 14:05 hotty 阅读(221) 评论(0) 推荐(1)
按照空格读取文件
摘要:#include <stdio.h>main(){char s1[20] = {0};char s2[20] = {0};char s3[20] = {0};int i=0;FILE *fp;fp = fopen("log.txt","r");fscanf(fp,"%s",s1);fscanf(fp,"%s",s2);fscanf(fp,"%s",s3);printf("%s\n%s\n%s\n",s1,s2,s3);}###代码二:#include <st 阅读全文
posted @ 2011-06-27 12:00 hotty 阅读(214) 评论(0) 推荐(0)
内存分配方式
摘要:原文:http://hi.baidu.com/knightzwy/blog/item/13eca673699ceb188701b02b.html内存分配方式-------------------------------------------------------------------------内存分配方式有三种:(1) 从静态存储区域分配。内存在程序编译的时候就已经分配好,这块内存在程序的整个运行期间都存在。 例如全局变量static变量。(2) 在栈上创建。在执行函数时,函数内局部变量的存储单元都可以在栈上创建,函数执行结束时这些存储 单元自动被释放。栈内存 分配运算内置于处理器的指 阅读全文
posted @ 2011-06-27 10:48 hotty 阅读(1209) 评论(0) 推荐(0)
堆和栈的区别
摘要:原文:http://hi.baidu.com/knightzwy/blog/item/e039135057ec436485352452.html堆和栈的区别一、预备知识—程序的内存分配一个由C/C++编译的程序占用的内存分为以下几个部分 1、栈区(stack)— 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等。其操作方式类似于数据结构中的栈。 2、堆区(heap) — 一般由程序员分配释放, 若程序员不释放,程序结束时可能由OS回收 。注意它与数据结构中的堆是两回事,分配方式倒是类似于链表,呵呵。 3、全局区(静态区)(static)—,全局变量和静态变量的存储是放在一块的,初始化的 阅读全文
posted @ 2011-06-27 10:44 hotty 阅读(330) 评论(0) 推荐(0)

1 2 下一页