Latest web development tutorials

C library functions - strerror ()

C standard library - <string.h> C standard library - <string.h>

description

C library functionschar * strerror (int errnum) Searching for flights from internal array error number errnum,and returns a pointer to an error message string pointer. error stringstrerror generated depends on the development platform and compiler.

statement

Here is () statement strerror function.

char *strerror(int errnum)

parameter

  • errnum - error number, usually errno.

return value

This function returns a pointer to a pointer to an error string, the error string describes error errnum.

Examples

The following example demonstrates the strerror () function is used.

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

int main ()
{
   FILE *fp;

   fp = fopen("file.txt","r");
   if( fp == NULL ) 
   {
      printf("Error: %s\n", strerror(errno));
   }
   
  return(0);
}

Let's compile and run the above program, which will produce the following results, as we try to open a file that does not exist:

Error: No such file or directory

C standard library - <string.h> C standard library - <string.h>