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

C語言入門必會標準庫函數速查表

     編輯:C 語言問答

C語言標準庫核心函數分類速查

掌握以下函數可覆蓋90%以上入門級編程需求:

輸入輸出函數 (stdio.h)

函數用途範例
printf格式化輸出printf("%d %.2f %s", n, f, str);
scanf格式化輸入scanf("%d %f", &n, &f);
putchar輸出單字元putchar('A');
getchar輸入單字元char c = getchar();
puts輸出字串換行puts("Hello");
fgets安全輸入字串fgets(buf, sizeof(buf), stdin);
fprintf/fscanf檔案格式化讀寫fprintf(fp, "%d", n);

數學函數 (math.h)

  • sqrt(x) 平方根
  • pow(x, y) x的y次方
  • abs(x) 整數絕對值
  • fabs(x) 浮點數絕對值
  • sin/cos/tan 三角函數(弧度制)
  • ceil/floor/round 向上/向下/四捨五入

字串處理 (string.h)

  • strlen 字串長度
  • strcpy/strncpy 複製
  • strcat/strncat 連接
  • strcmp/strncmp 比較
  • strchr/strstr 查找字元/子串
  • memset/memcpy 記憶體填充/複製

記憶體管理 (stdlib.h)

  • malloc/calloc/realloc 動態分配
  • free 釋放記憶體
  • exit 終止程式
  • rand/srand 隨機數生成
  • atoi/atof/atol 字串轉數值

字元判斷 (ctype.h)

  • isdigit/isalpha/isalnum 數字/字母/字母數字
  • islower/isupper 大小寫判斷
  • tolower/toupper 大小寫轉換
  • isspace 空白字元判斷

學習建議

查閱 man 3 函數名 (Linux) 或 MSDN 文檔(Windows)了解完整原型、返回值、錯誤碼。實戰中遇到需求先查標準庫,避免重複造輪子。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved