For some library functions, if an error occurs during the library function execution, an error code is set in the macro errno defined in the header file <errno.h> contained in the standard library.
Error messages are defined in the error codes so that error messages can be output. The following shows an example of an error message output program.
Since the file pointer of NULL is passed to the fclose function as an argument, an error will occur. In this case, an error code corresponding to errno is set. |
The strerror function returns a pointer of the string literal of the corresponding error message when the error code is passed as an argument. An error message is output by specifying the output of the string literal of the printf function. |
List of Standard Library Error Messages