有了域名和云主机怎么做网站,淘宝客网站建设公司,一级造价工程师报考条件及时间,嘉兴cms模板建站C语言stderr、errno、strerror、perror
stderr 是标准错误输出#xff0c;类型为 FILE* #xff1b; errno 宏是运行时最近一次的错误代码#xff0c;正常运行时值为 0#xff1b; strerror() 函数用于获取 errno 错误代码对应的错误信息字符串#xff1b; perror() 函数…C语言stderr、errno、strerror、perror
stderr 是标准错误输出类型为 FILE* errno 宏是运行时最近一次的错误代码正常运行时值为 0 strerror() 函数用于获取 errno 错误代码对应的错误信息字符串 perror() 函数用于打印 errno 的错误信息。是一个封装的帮助函数。
#include stdio.h
#include stdlib.h
#include errno.h
#include string.h
int main(int argc[],char *argv[]) {malloc(1);printf(errno %d\n,errno);perror(perror);printf(strerror: %s\n,strerror(errno));malloc(-1);printf(errno %d\n,errno);perror(perror);printf(strerror: %s\n,strerror(errno));return 0;
}运行结果
errno 0
perror: Success
strerror: Success
errno 12
perror: Cannot allocate memory
strerror: Cannot allocate memory