C函数库errno.h概况

在linux中使用c语言编程时,errno是个很有用的动动。他可以把最后一次调用c的方法的错误代码保留。但是如果最后一次成功的调用c的方法,errno不会改变。因此,只有在c语言函数返回值异常时,再检测errno。

代码:

errno = 0;
int s = sqrt(-1);
if (errno) {
printf("error: %s\n", strerror(errno));
}

原文地址:https://www.cnblogs.com/smallbird/p/7448078.html