代码很简单,testc.c

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <errno.h>                                                           
 4 #include <string.h>
 5 
 6 #define Numerous 0xFFFFFFFFFFFFFF
 7 
 8 int main(int argc, char **argv)
 9 {
10     char *ptrCh = (char *)malloc(sizeof(char) * Numerous);
11     if(ptrCh == NULL){
12         printf("There is an error: %s\n", strerror(errno));
13     }
14 
15     return 0;
16 }

结果是显而易见的

There is an error: Cannot allocate memory

使用函数strerror输出系统的错误,使用errno获取系统的错误的详细信息。

相关文章:

  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
  • 2022-02-19
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
  • 2022-02-09
猜你喜欢
  • 2021-12-08
  • 2021-05-21
  • 2021-06-27
  • 2022-01-17
  • 2021-12-05
  • 2022-01-12
相关资源
相似解决方案