C 庫 - <stdlib.h>



stdlib.h 標頭檔案定義了四種變數型別、幾個宏以及用於執行常規函式的各種函式。

庫變數

以下是標頭檔案 stdlib.h 中定義的變數型別:

序號 變數 & 描述
1

size_t

這是一個無符號整型,是 sizeof 關鍵字的結果。

2

wchar_t

這是一個整數型別,大小與一個 字元常量相同。

3

div_t

這是 div 函式返回的結構。

4

ldiv_t

這是 ldiv 函式返回的結構。

庫宏

以下是標頭檔案 stdlib.h 中定義的宏:

序號 宏 & 描述
1

NULL

此宏是空指標常量的值。

2

EXIT_FAILURE

這是 exit 函式在失敗情況下返回的值。

3

EXIT_SUCCESS

這是 exit 函式在成功情況下返回的值。

4

RAND_MAX

此宏是 rand 函式返回的最大值。

5

MB_CUR_MAX

此宏是多位元組字元集中位元組的最大數量,不能大於 MB_LEN_MAX。

庫函式

以下是標頭檔案 stlib.h 中定義的函式:

序號 函式 & 描述
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)

將引數 str 指向的字串轉換為長整數(long int 型別)。

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

將引數 str 指向的字串轉換為無符號長整數(unsigned long int 型別)。

7 void *calloc(size_t nitems, size_t size)

分配請求的記憶體並返回指向它的指標。

8 void free(void *ptr

釋放之前透過呼叫 calloc、mallocrealloc 分配的記憶體。

9 void *malloc(size_t size)

分配請求的記憶體並返回指向它的指標。

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

嘗試調整之前使用 malloccalloc 呼叫分配的、由 ptr 指向的記憶體塊的大小。

11 void abort(void)

導致程式異常終止。

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

導致程式正常終止時呼叫指定的函式 func

13 void exit(int status)

導致程式正常終止。

14 char *getenv(const char *name)

搜尋由 name 指向的環境字串,並將關聯的值返回到字串。

15 int system(const char *string)

將由 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)

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

22 int rand(void)

返回 0 到 RAND_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)

將引數 str 指向的多位元組字元字串轉換為 pwcs 指向的陣列。

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 給出的多位元組字元對應的程式碼。

廣告