首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> C >> C 語言問答

C語言標準庫常用函數分類速查表(含頭文件)

     編輯:C 語言問答

C 標準庫 29 個頭文件功能分類總表

頭文件主要功能領域代表函數/類型/巨集
<assert.h>斷言`assert`
<complex.h>複數運算 (C99)`complex`, `I`, `cabs`, `csin`, `cpow`
<ctype.h>字符分類與轉換`isdigit`, `isalpha`, `tolower`, `toupper`, `isspace`
<errno.h>錯誤碼`errno`, `EDOM`, `ERANGE`, `EILSEQ`
<fenv.h>浮點環境 (C99)`feclearexcept`, `fegetround`, `feraiseexcept`, `FE_*`
<float.h>浮點型別極限`FLT_MAX`, `DBL_EPSILON`, `LDBL_MANT_DIG`, `DECIMAL_DIG`
<inttypes.h>定寬整數格式轉換 (C99)`PRId64`, `SCNd32`, `intmax_t`, `uintptr_t`, `imaxabs`, `imaxdiv`
<iso646.h>替代運算子拼寫`and`, `or`, `not`, `xor`, `bitand`, `bitor`, `compl`
<limits.h>整數型別極限`INT_MAX`, `LONG_MIN`, `CHAR_BIT`, `LLONG_MAX`
<locale.h>地區設定`setlocale`, `localeconv`, `struct lconv`
<math.h>數學函數`sin`, `cos`, `tan`, `sqrt`, `log`, `exp`, `pow`, `hypot`, `fma`, `floor`, `ceil`
<setjmp.h>非局部跳轉`setjmp`, `longjmp`, `jmp_buf`
<signal.h>信號處理`signal`, `raise`, `SIGINT`, `SIGSEGV`, `SIGTERM`, `sig_atomic_t`
<stdalign.h>對齊關鍵字 (C11)`alignas`, `alignof`, `max_align_t`
<stdarg.h>可變參數`va_list`, `va_start`, `va_arg`, `va_end`, `va_copy`
<stdatomic.h>原子操作 (C11)`atomic_int`, `atomic_load`, `atomic_store`, `atomic_compare_exchange_strong`, `memory_order_*`
<stdbool.h>布林型別 (C99)`bool`, `true`, `false`, `__bool_true_false_are_defined`
<stddef.h>通用定義`size_t`, `ptrdiff_t`, `NULL`, `offsetof`, `max_align_t`
<stdint.h>定寬整數型別 (C99)`int8_t`, `uint32_t`, `intptr_t`, `SIZE_MAX`, `INT64_C`, `UINT32_MAX`
<stdio.h>輸入輸出`printf`, `scanf`, `fopen`, `fclose`, `fread`, `fwrite`, `fgets`, `fprintf`, `snprintf`, `FILE`, `stdin`, `stdout`, `stderr`, `perror`
<stdlib.h>通用工具`malloc`, `free`, `calloc`, `realloc`, `exit`, `abort`, `atexit`, `rand`, `srand`, `strtol`, `strtod`, `abs`, `labs`, `llabs`, `div`, `ldiv`, `bsearch`, `qsort`, `getenv`, `system`
<stdnoreturn.h>不返回函數標記 (C11)`noreturn`
<string.h>字符串與記憶體操作`strcpy`, `strncpy`, `strcat`, `strncat`, `strcmp`, `strncmp`, `strlen`, `strchr`, `strrchr`, `strstr`, `memcpy`, `memmove`, `memset`, `memcmp`, `memchr`
<tgmath.h>型別泛型數學 (C99)`sin`, `cos`, `sqrt` 等自動根據實參型別選擇 `float`/`double`/`long double`/`complex` 版本
<threads.h>執行緒 (C11, 選擇性實現)`thrd_create`, `thrd_join`, `mtx_init`, `mtx_lock`, `mtx_unlock`, `cnd_init`, `cnd_wait`, `cnd_signal`, `cnd_broadcast`, `thread_local`
<time.h>日期時間`time`, `clock`, `difftime`, `strftime`, `gmtime`, `localtime`, `struct tm`, `timespec`, `CLOCKS_PER_SEC`, `TIME_UTC`
<uchar.h>Unicode 字符 (C11)`char16_t`, `char32_t`, `c16rtomb`, `mbrtoc16`, `c32rtomb`, `mbrtoc32`, `mbstate_t`
<wchar.h>寬字符`wchar_t`, `wprintf`, `wcscpy`, `wcslen`, `wcscmp`, `mbrtowc`, `wcrtomb`, `wcsrtombs`
<wctype.h>寬字符分類`iswalpha`, `iswdigit`, `iswspace`, `towlower`, `towupper`, `wctrans`, `wctype`

高頻核心「五大金剛」頭文件(建議每個 .c 都包含)

#include <stddef.h>   // size_t, ptrdiff_t, NULL, offsetof
#include <stdint.h>  // int32_t, uint64_t, SIZE_MAX, INT_MAX
#include <stdio.h>   // I/O
#include <stdlib.h>  // 記憶體/轉換/排序/環境
#include <string.h>  // 字串/記憶體操作

常用功能 → 頭文件快速導引

  • 動態記憶體:`stdlib.h` (`malloc`/`free`/`realloc`/`calloc`)
  • 格式化 I/O:`stdio.h` (`printf`/`scanf`/`snprintf`/`fopen`)
  • 字串操作:`string.h` (`strlen`/`strcpy`/`strcmp`/`strchr`/`strstr`)
  • 記憶體操作:`string.h` (`memcpy`/`memmove`/`memset`/`memcmp`)
  • 定寬整數:`stdint.h` (`int32_t`/`uint64_t`/`intptr_t`)
  • 布林型別:`stdbool.h` (`bool`/`true`/`false`)
  • 斷言:`assert.h` (`assert`)
  • 時間:`time.h` (`time`/`clock`/`strftime`/`localtime`)
  • 錯誤碼:`errno.h` (`errno`)
  • 可變參數:`stdarg.h` (`va_list`/`va_start`/`va_arg`/`va_end`)
  • 數學:`math.h` (`sin`/`cos`/`sqrt`/`log`/`exp`/`hypot`)
  • 字符分類:`ctype.h` (`isdigit`/`isalpha`/`tolower`/`toupper`)
  • 排序/二分搜尋:`stdlib.h` (`qsort`/`bsearch`)
  • 原子操作:`stdatomic.h` (`atomic_*`)
  • 執行緒:`threads.h` (`thrd_*`/`mtx_*`/`cnd_*`)

使用提醒

  • **嚴格包含所需頭文件** — 不要依賴傳遞性包含(如 `stdio.h` 可能包含 `stddef.h`,但標準不保證)。
  • **C++ 專案用 `` 形式** — ``、``、``、``、``,名稱在 `std` 命名空間。
  • **避免非標準頭文件** — `conio.h`、`malloc.h`、`memory.h`、`alloc.h`、`dirent.h` (POSIX)、`unistd.h` (POSIX) — 跨平台請用標準庫或抽象層。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved