strerror Function

Gets an internal error message.

Include

<string.h>

Prototype

char *strerror(int errcode);

Argument

errcode
number of the error code

Return Value

Returns a pointer to an internal error message string corresponding to the specified error code errcode.

Remarks

The array pointed to by strerror may be overwritten by a subsequent call to this function.

Example

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

int main(void)
{
  FILE *myfile;

  if ((myfile = fopen("samp.fil", "r+")) == NULL)
    printf("Cannot open samp.fil: %s\n", 
            strerror(errno));
  else
    printf("Success opening samp.fil\n");
  fclose(myfile);
}

Example Output

Cannot open samp.fil: file open error