C - Error Handling, Exception Handling in C, strerror function
Tutorials Point


  Learning C
  C Function References
  C Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     About TP     Advertising  

C - strerror function

previous

Synopsis:

#include <stdio.h>
#include <errno.h>

char *strerror(int  errnum );

Description:

The strerror() function returns a string describing the error code passed in the argument errnum. Here passed value will be errno

Return Value

The strerror() function returns the appropriate error description string, or an unknown error message if the error code is unknown. The value of errno is not changed for a successful call, and is set to a nonzero value upon error.

Example

#include <stdio.h>
#include <errno.h>

extern int errno ;

int main ()
{
  FILE * pFile;
  pFile = fopen ("unexist.ent","rb");
  if (pFile == NULL)
  {
    printf( "Error Value is : %s\n", strerror(errno) );
  }
  else
    fclose (pFile);
  return 0;
}

If file unexist.ent does not exit then it will produce following result:

Error Value is : No such file or directory


previous Printer Friendly

Advertisements


  

Advertisements



Advertisements