C語言中關於錯誤輸出的函式

2021-07-03 13:54:49 字數 1414 閱讀 8649

1.errno

說明:errno是乙個全域性整形變數,定義在errno.c,宣告在errno.h

標頭檔案:#include

功能:輸出出錯原因

示例

#include

#include

#include

#include

#include

int main()

close(fd);

return 0;

結果:fail to open, errno is: 2

2.strerror()

宣告:char * strerror( int errno );

標頭檔案:#include

功能:根據錯誤號返回錯誤的描述

返回值:返回出錯字串

示例

#include

#include

#include

#include

#include

#include

int main()

close(fd);

return 0;

}結果:fail to open, the reason is: no such file or directory

3.perror()

宣告:void perror( const char *pszinfo );

標頭檔案:#include

#include

功能:char *pszinfo表示要輸出的字串,系統自動將使用errno變數對映得到的錯誤描述字串連線在引數字串後,該字串不需要新增'\n',perror()函式會自動新增。

返回值:無返回值

示例

#include

#include

#include

#include

#include

#include

int main()

close(fd);

return 0;

}結果:fail to open: no such file or directory

關於C語言中的memset函式

1.對於陣列初始化為0操作,常用 memset a,0,sizeof a 替代迴圈 for i 0 i2.將陣列初始化為無窮大的情況,例如floyd演算法。通常對於 32位int有符號數,我們將 無窮大inf 設為 0x3f3f3f3f define inf 0x3f3f3f3f 為什麼不設 inf...

C語言中關於函式的總結

函式意義 函式引數 函式設計原則 函式與巨集你覺不覺得c語言基礎知識概念在頭腦裡沒有形成知識體系?是否比較模糊比較亂?這就對了?我之前也是,有些知識點時間長了容易忘或者混淆,有些初學者抓不住重點覺得c語言複雜,難!實不相瞞,我也是這樣的感受,於是我想是時候整體的把c語言給好好的總結一下了,這樣形成乙...

C語言中printf()函式格式輸出

printf 函式是格式輸出函式,請求printf 列印變數的指令取決與變數的型別 例如,在列印整數是使用 d符號,在列印字元是用 c 符號 這些符號被稱為轉換說明 因為它們指定了如何不資料轉換成可顯示的形式 下列列出的是 標準peintf 提供的各種轉換說明 轉換說明及作為結果的列印輸出 a 浮點...