strerror function returns error message
Syntax
C strerror function has the following format.
char *strerror(int errnum);
Header
C strerror function
is from header file string.h
.
Description
C strerror function returns error message associated with the errnum
.
Example
Print an implementation-defined error message on the screen:
#include<string.h>
#include<stdio.h>
int main(void){
printf(strerror(10));/*from w w w .j a va2 s . c om*/
}
The following code uses strerror in case of file open error.
#include <stdio.h>
#include <string.h>
#include <errno.h>
/*from w w w .jav a 2 s. c o m*/
int main ()
{
FILE * pFile;
pFile = fopen ("unexist.ent","r");
if (pFile == NULL)
printf ("Error opening file unexist.ent: %s\n",strerror(errno));
return 0;
}
The code above generates the following result.