English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Online Tools

O)

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Flow Control

C Language Structure

C Language File

C Other

C Language Reference Manual

C Standard Library - <errno.h>

C Library Macro – errno Usage and Example

Description C Library Macro extern int errno

It is set by system calls and some library functions indicate what went wrong during error events.

Declaration

Below is the declaration of the errno macro.

extern int errno

  • Return Value

Parameter

  • Return Value

NA

Online Example

Example
#include <stdio.h>
#include <errno.h>
 
#include <string.h>
 
extern int errno;
{
   int main() *FILE
 
   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's compile and run the above program when the file file.txt The following result will be produced if it does not exist:

Value of errno: 2
Error occurred when opening the file: No such file or directory

C Standard Library - <errno.h>