日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux中以A开头的函数使用方式历程及详解

發布時間:2025/3/15 linux 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux中以A开头的函数使用方式历程及详解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

A開頭的Linux C函數

abort

異常終止程序

abort函數在調用的時候,會觸發SIGABRT信號

#include <stdlib.h> #include <signal.h> #include <stdio.h> #include <unistd.h>static void signalHandler(int sig);// 信號處理函數 void signalHandler(int sig) {if(sig == SIGABRT) //對應ctrl+c{printf("abort 函數被調用,觸發SIGABRT信號量 。\n");} } //以下是主函數 int main(int argc,char *argv[]) {signal(SIGABRT, signalHandler); //注冊SIGINT對應的處理函數abort();printf("程序走不到這里。\n");return 0; }

abs

對整數求絕對值的函數

#include <stdlib.h> #include <signal.h> #include <stdio.h> #include <unistd.h> /*┌──────────────────────────────┬───────────────┬─────────┐│Interface │ Attribute │ Value │├──────────────────────────────┼───────────────┼─────────┤│abs(), labs(), llabs(), imax‐ │ Thread safety │ MT-Safe ││abs() │ │ │└──────────────────────────────┴───────────────┴─────────┘ */ int main(int argc, char const *argv[]) {/* code */printf("abs(-1) = [%d]\n", abs(-1));return 0; }

acos

反余弦函數

#include <stdlib.h> #include <signal.h> #include <stdio.h> #include <unistd.h> #include <math.h>/*┌─────────────────────────┬───────────────┬─────────┐│Interface │ Attribute │ Value │├─────────────────────────┼───────────────┼─────────┤│acos(), acosf(), acosl() │ Thread safety │ MT-Safe │└─────────────────────────┴───────────────┴─────────┘ */int main(int argc, char const *argv[]) {double real = acos(-0.5);printf("%lf\n", real);return 0; }

asctime time localtime

系統時間獲取函數,注意這幾個函數的時間受校時函數的影響

time() returns the time as the number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC)

loacaltime() 將time_t 結構的數據,轉換為對應的日歷時間,詳見tm結構體

asctime() 將日歷形式結構體時間數據轉換為對應的字符串

#include <stdlib.h> #include <signal.h> #include <stdio.h> #include <unistd.h> #include <math.h> #include <time.h> #include <string.h>#if 0 struct tm {int tm_sec; /* Seconds. [0-60] (1 leap second) */int tm_min; /* Minutes. [0-59] */int tm_hour; /* Hours. [0-23] */int tm_mday; /* Day. [1-31] */int tm_mon; /* Month. [0-11] */int tm_year; /* Year - 1900. */int tm_wday; /* Day of week. [0-6] */int tm_yday; /* Days in year.[0-365] */int tm_isdst; /* DST. [-1/0/1]*/long int __tm_gmtoff; const char *__tm_zone; }; #endifint main(int argc, char const *argv[]) {//定義時間結構體指針,結構體值見注釋struct tm *pTm = NULL;time_t nowTime;char *pSzAscTime = NULL;memset(&nowTime, 0 , sizeof(nowTime));nowTime = time(NULL);pTm = localtime(&nowTime);pSzAscTime = asctime(pTm);printf("Asc time = %s", pSzAscTime);return 0; }

asin

反正弦函數

#include <stdlib.h> #include <signal.h> #include <stdio.h> #include <unistd.h> #include <math.h>int main(int argc, char const *argv[]) {double real = asin(-0.5);printf("%lf\n", real);return 0; }

assert

assert()函數是診斷函數,診斷一個表達式是否為真,只有為真才能繼續執行

#include <stdlib.h> #include <signal.h> #include <stdio.h> #include <unistd.h> #include <math.h> #include <assert.h>/*** 診斷表達式的真值* */int main(int argc, char const *argv[]) {assert(1);return 0; }

atan

atan() 反正弦函數

#include <stdlib.h> #include <signal.h> #include <stdio.h> #include <unistd.h> #include <math.h>int main(int argc, char const *argv[]) {double real = atan(-0.5);printf("%lf\n", real);return 0; }

atexit

atexit() 在程序要退出時注冊要調用的函數

該函數在做項目,一個進程中有多個線程,又申請內存需要釋放的時候,非常有用,將需要釋放的內存放到被注冊的函數里面,無論在那個線程里面退出程序,都會出發釋放資源的函數,這樣就不用擔心資源的釋放問題了。

#include <stdlib.h> #include <signal.h> #include <stdio.h> #include <unistd.h> #include <math.h>// C語言中用于注冊 正常退出時調用的函數 // 當程序調用exit函數進行推出時就會先調用atexit函數注冊的函數 #define TRUE 1 //真 #define FALSE 0 //假 #define YES 1 //是 #define NO 0 //否 #define OK 0 //通過 #define ERROR -1 //錯誤void callHnadler(void);void callHnadler(void) {printf("這個函數會在函數退出前調用一次\n"); }int main(int argc, char const *argv[]) {int ret = ERROR; ret = atexit(callHnadler);if(OK != ret){printf("atexit register callHandler function failed\n");}return 0; }

atof

將字符串轉換為浮點數的函數

#include <stdlib.h> #include <signal.h> #include <stdio.h> #include <unistd.h> #include <math.h>// 將字符串轉換為浮點數的函數int main(int argc, char const *argv[]) {printf("0.12345 = [%f]\n", atof("0.12345"));return 0; }

atoi

將字符串轉換為整數的函數

#include <stdlib.h> #include <signal.h> #include <stdio.h> #include <unistd.h> #include <math.h>// 將字符串轉化為整數的函數int main(int argc, char const *argv[]) {printf("12345 = [%d]\n", atoi("12345"));return 0; }

atol

將字符串轉換為長整型的函數

#include <stdlib.h> #include <signal.h> #include <stdio.h> #include <unistd.h> #include <math.h>// 將字符串轉化為整數的函數int main(int argc, char const *argv[]) {printf("12345 = [%d]\n", atol("12345"));return 0; }

掃碼關注,一起探究linux編程的樂趣

總結

以上是生活随笔為你收集整理的linux中以A开头的函数使用方式历程及详解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。