C语言错误处理

来源:互联网 发布:硬笔字 知乎 编辑:程序博客网 时间:2024/04/28 21:26
#include <stdio.h>#include <errno.h>#include <string.h>extern int errno ;int main (){   FILE * pf;   int errCode;   pf = fopen ("test.txt", "rb");   if (pf == NULL){      errCode = errno;      //三种输出错误的方法      fprintf(stderr, "ErrorCode: %d\n", errno);      perror("print error by perror");      fprintf(stderr, "error in opening file : %s\n", strerror( errCode ));   }else{      fclose (pf);   }   return 0;}
0 0
原创粉丝点击