Thursday, 13 November 2014

Error Handling in C

In C we can handle errors using special variable called errno which is defined in <errno.h> header file. Whenever any error occurs during execution of the c program, the error number is stored in errno variable. To print the error description, we use below function call.

strerror( errno);

We can clear error number using below line.

Errno = 0;

#include <stdio.h>
#include <errno.h>
#include <string.h>
extern int errno ;
int main ()
   FILE * pf;
   pf = fopen ("abdc.txt", "r");

   if (pf == NULL)
      printf("errno contains value : %d\n", errno);
      printf("Human readable error description : %s\n", strerror( errno ));
      fclose (pf);
   return 0;

Sponsored Links

Popular Posts



Google+ Followers

Google+ Badge