c/c++标准库-stdlib.h

来源:互联网 发布:android 与js交互 编辑:程序博客网 时间:2024/05/16 16:01

stdlib.h中头文件定义了四个变量类型,用于执行一般函数的几个宏和各类函数。

 

库变量

 

以下是在头文件stdlib.h中定义的变量类型:

 

S.N. 变量和说明

1 size_t

这是一个无符号整数类型的sizeof关键字的结果。

2 wchar_t

这是一个整数类型的宽字符常量的大小。

3 div_t

这是结构的div函数返回。

4 ldiv_t

这是由 ldiv 函数返回的结构。

库宏

 

以下是在头文件stdlib.h中定义的宏:

 

S.N. 宏与说明

1 NULL

这个宏是一个空指针常量的值。

2 EXIT_FAILURE

这是退出功能,在发生故障的情况下,返回的值。

3 EXIT_SUCCESS

这是exit函数返回成功的情况下的值。

4 RAND_MAX

这个宏是由rand函数传回的最大值。

5 MB_CUR_MAX

这个宏不能大于MB_LEN_MAX的多字节字符集的最大字节数。

库函数

 

以下是在头stdio.h中定义的函数:

 

S.N. 功能及说明

1 double atof(const char *str)

转换参数str指向的字符串到浮点数(double类型)。

2 int atoi(const char *str)

转换参数str指向的字符串为整数(int型)。

3 long int atol(const char *str)

转换字符串参数str指向一个长整型(类型为long int

4 double strtod(const char *str, char **endptr)

转换参数str指向的字符串到浮点数(double类型)。

5 long int strtol(const char *str, char **endptr, int base)

字符串转换成一个长整型(类型为long int)参数str指向。

6 unsigned long int strtoul(const char *str, char **endptr, int base)

转换字符串参数str指向一个无符号长整型(unsigned long型整数)。

7 void *calloc(size_t nitems, size_t size)

分配请求的内存,并返回一个指向它的指针。

8 void free(void *ptr

callocmallocrealloc调用先前分配的回收内存。

9 void *malloc(size_t size)

Allocates the requested memory and returns a yiibaier to it.

10 void *realloc(void *ptr, size_t size)

尝试调整的内存块的大小由ptr指向先前调用malloccalloc的分配。

11 void abort(void)

导致程序异常终止。

12 int atexit(void (*func)(void))

导致指定的函数功能,当程序正常终止时,被调用。

13 void exit(int status)

导致正常程序终止。

14 char *getenv(const char *name)

name所指向环境字符串的搜索,并返回相关的字符串的值。

15 int system(const char *string)

字符串指定的命令被传递到主机环境中,要执行的命令处理器。

16 void *bsearch(const void *key, const void *base, size_t nitems, size_t size, int (*compar)(const void *, const void *))

执行二进制搜索。

17 void qsort(void *base, size_t nitems, size_t size, int (*compar)(const void *, const void*))

对数组排序

18 int abs(int x)

返回x的绝对值。

19 div_t div(int numer, int denom)

数(分子numer)除以分母(分母denom)。

20 long int labs(long int x)

返回x的绝对值。

21 ldiv_t ldiv(long int numer, long int denom)

数(分母denom)除以分母(分子numer)。

22 int rand(void)

返回一个取值范围为0RAND_MAX之间的伪随机数。

23 void srand(unsigned int seed)

这个函数使用rand函数随机数生成器的种子。

24 int mblen(const char *str, size_t n)

返回参数str指向一个多字节字符的长度。

25 size_t mbstowcs(schar_t *pwcs, const char *str, size_t n)

转换pwcs 指向的数组参数str所指向的多字节字符的字符串。

26 int mbtowc(whcar_t *pwc, const char *str, size_t n)

检查参数str所指向的多字节字符。

27 size_t wcstombs(char *str, const wchar_t *pwcs, size_t n)

存储在数组pwcs  多字节字符并存入字符串str中的代码转换。

28 int wctomb(char *str, wchar_t wchar)

检查参数wchar多字节字符对应的代码。 

原创粉丝点击