perror


perror

Print an error message corresponding to the value of errno

 #include <stdio.h> void perror ( const char *string  ); 

The perror( ) function prints a message to the standard error stream. The output includes first the string referenced by the pointer argument, if any; then a colon and a space, then the error message that corresponds to the current value of the errno variable, ending with a newline character.

Example

 #define MSGLEN_MAX 256 FILE *fp; char msgbuf[MSGLEN_MAX] = ""; if (( fp = fopen( "nonexistentfile", "r" )) == NULL ) {   snprintf( msgbuf, MSGLEN_MAX, "%s, function %s, file %s, line %d",             argv[0], _  _func_  _, _  _FILE_  _, _  _LINE_  _ );   perror( msgbuf );   return errno; } 

Assuming that there is no file available named nonexistentfile, this code results in output like the following on stderr:

 ./perror, function main, file perror.c, line 18: No such file or directory 

See Also

strerror( )



C(c) In a Nutshell
C in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596006977
EAN: 2147483647
Year: 2006
Pages: 473

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net