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

C標準庫函數速查手冊(A 開頭):abort/abs/absread/access/acos/allocmem/arc/asctime/asin/assert/atan/atan2/atexit/atof/atoi/atol

     編輯:關於C語言

A 開頭標準庫函數速查

本文匯總 C 標準庫及常見擴展庫中以 字母 A 開頭 的函數,包含功能說明、函數原型、頭文件要求與最小可運行示例。適用於快速查閱與參考。

函數列表

abort - 異常終止進程


#include 
void abort(void);
// 不執行清理(atexit、緩衝區刷新),直接終止,返回非零碼給宿主環境。
int main() {
    printf("Calling abort()\n");
    abort();
    return 0;  // 永不執行
}

abs - 整數絕對值


#include 
int abs(int i);
// 返回 |i|,注意 INT_MIN 絕對值溢出為未定義行為。
int main() {
    int n = -1234;
    printf("abs(%d) = %d\n", n, abs(n));
}

absread / abswrite - 絕對磁盤扇區讀寫 (DOS/BIOS 專用)


#include 
int absread(int drive, int nsects, int sectno, void *buffer);
int abswrite(int drive, int nsects, int sectno, void *buffer);
// 直接讀寫磁盤扇區,現代保護模式 OS 禁止用戶態調用,僅限實模式/DOS 環境。

access - 檢查文件訪問權限


#include   // POSIX
#include       // Windows
int access(const char *filename, int mode);
// mode: F_OK(存在), R_OK(讀), W_OK(寫), X_OK(執行)。返回 0 成功,-1 失敗置 errno。
int file_exists(const char *name) { return access(name, F_OK) == 0; }

acos - 反余弦


#include 
double acos(double x);
// 定義域 [-1,1],返回值 [0, π] 弧度。
int main() {
    printf("acos(0.5) = %f rad = %f deg\n", acos(0.5), acos(0.5)*180/M_PI);
}

allocmem - 分配 DOS 內存段 (實模式專用)


#include 
int allocmem(unsigned size, unsigned *segp);
// size 以段落(16字節)為單位。現代 OS 不適用。

arc - 繪制圓弧 (BGI 圖形庫)


#include 
void far arc(int x, int y, int stangle, int endangle, int radius);
// 以 (x,y) 為圓心,半徑 radius,從 stangle 到 endangle 繪弧(度數,逆時針)。
// 需 initgraph 初始化圖形模式。

asctime - tm 結構轉字符串


#include 
char *asctime(const struct tm *tptr);
// 格式固定:"Www Mmm dd hh:mm:ss yyyy\n\0",返回靜態緩衝區指針(非線程安全)。
int main() {
    time_t t = time(NULL);
    printf("%s", asctime(localtime(&t)));
}

asin - 反正弦


#include 
double asin(double x);
// 定義域 [-1,1],返回值 [-π/2, π/2]。

assert - 斷言調試宏


#include 
void assert(int expression);
// expression 為 0 時輸出錯誤信息並調用 abort()。定義 NDEBUG 宏可禁用所有 assert。
void add(int *p) { assert(p != NULL); /* ... */ }

atan - 反正切


#include 
double atan(double x);
// 返回值 [-π/2, π/2]。

atan2 - 兩參數反正切 (完整象限)


#include 
double atan2(double y, double x);
// 返回值 [-π, π],自動處理象限,x=0 時不會除零。
// 極坐標角度計算首選:angle = atan2(y, x);

atexit - 註冊程序退出處理函數


#include 
int atexit(void (*func)(void));
// 程序正常退出時(exit/return from main)按註冊逆序調用。最多註冊 32/64 個(實現定義)。
void bye1() { puts("bye1"); }
void bye2() { puts("bye2"); }
int main() { atexit(bye1); atexit(bye2); return 0; }
// 輸出: bye2\nbye1\n

atof - 字符串轉 double


#include 
double atof(const char *nptr);
// 等價於 strtod(nptr, NULL)。無錯誤檢查,轉換失敗返回 0.0。

atoi - 字符串轉 int


#include 
int atoi(const char *nptr);
// 等價於 (int)strtol(nptr, NULL, 10)。溢出行為未定義,無錯誤檢查。
// 推薦用 strtol/strtoll 替代。

atol - 字符串轉 long


#include 
long atol(const char *nptr);
// 等價於 strtol(nptr, NULL, 10)。同樣無錯誤檢查。

使用建議

  • 字符串轉數值:優先用 strtol/strtod/strtoul 等,提供完整錯誤檢查(endptr、errno)。
  • 數學函數:編譯鏈接需加 -lm (GCC/Clang) 鏈接數學庫。
  • 斷言:僅用於檢查不可能為假的邏輯前提(內部不變量),不用於運行時錯誤處理(如文件打開失敗)。
  • 舊式圖形/內存/DOS 函數:arc、allocmem、absread 僅供歷史代碼維護參考,現代開發請用 SDL/OpenGL/Vulkan、malloc/mmap、文件 I/O 替代。

快速索引表

函數功能分類頭文件標準
abort進程控制stdlib.hC89
abs數學stdlib.hC89
absread/write底層磁盤 (DOS)bios.h/dos.h非標準
access文件系統unistd.h/io.hPOSIX/Win
acos/asin/atan/atan2三角反函數math.hC89
allocmem內存管理 (DOS)dos.h非標準
arc圖形 (BGI)graphics.h非標準
asctime時間格式化time.hC89
assert調試斷言assert.hC89
atexit進程退出鉤子stdlib.hC89
atof/atoi/atol字符串轉數值stdlib.hC89
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved