
- The C Standard Library
- C Library - Home
- C Library - <assert.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <float.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdarg.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <time.h>
- C Standard Library Resources
- C Library - Quick Guide
- C Library - Useful Resources
- C Library - Discussion
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
C library Macro - errno
Description
The C library macro extern int errno is set by system calls and some library functions in the event of an error to indicate if anything went wrong.
Declaration
Following is the declaration for errno macro.
extern int errno
Parameters
NA
Return Value
NA
Example
The following example shows the usage of errno Macro.
#include <stdio.h> #include <errno.h> #include <string.h> extern int errno ; int main () { FILE *fp; fp = fopen("file.txt", "r"); if( fp == NULL ) { fprintf(stderr, "Value of errno: %d\n", errno); fprintf(stderr, "Error opening file: %s\n", strerror(errno)); } else { fclose(fp); } return(0); }
Let us compile and run the above program that will produce the following result in case file file.txt does not exist −
Value of errno: 2 Error opening file: No such file or directory
errorno_h.htm
Advertisements