perror() strerror() _strerror()

來源:互聯網
上載者:User

定義函數
  void perror(const char *s); perror ("open_port");
函數說明
  perror ( )用 來 將 上 一 個 函 數 發 生 錯 誤 的 原 因 輸 出 到 標 准 裝置 (stderr) 。參數 s 所指的字串會先列印出,後面再加上錯誤原因字串。此錯誤原因依照全域變數errno 的值來決定要輸出的字串。
  在庫函數中有個errno變數,每個errno值對應著以字串表示的錯誤類型。當你調用"某些"函數出錯時,該函數已經重新設定了errno的值。perror函數只是將你輸入的一些資訊和現在的errno所對應的錯誤一起輸出

#include <stdio.h>  int main(void)  {  FILE *fp ;  fp = fopen( "/root/noexitfile", "r+" );  if ( NULL == fp )  {  perror("/root/noexitfile");  }  return 0;  }/*運行結果  [root@localhost io]# gcc perror.c  [root@localhost io]# ./a.out  /root/noexitfile: No such file or directory*/

 

char *strerror( int errnum );把一個錯誤numb作為參數,然後返回錯誤numb所對應的錯誤語段,一般用errno。

char *_strerror( const char *strErrMsg ); strErrMsg+擷取系統錯誤資訊或列印使用者程式錯誤資訊。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.