Tutorial by Examples

When a standard library function fails, it often sets errno to the appropriate error code. The C standard requires at least 3 values for errno be set: ValueMeaningEDOMDomain errorERANGERange errorEILSEQIllegal multi-byte character sequence
If perror is not flexible enough, you may obtain a user-readable error description by calling strerror from <string.h>. int main(int argc, char *argv[]) { FILE *fout; int last_error = 0; if ((fout = fopen(argv[1], "w")) == NULL) { last_error = errno; ...
To print a user-readable error message to stderr, call perror from <stdio.h>. int main(int argc, char *argv[]) { FILE *fout; if ((fout = fopen(argv[1], "w")) == NULL) { perror("fopen: Could not open file for writing"); return EXIT_FAILURE; } r...

Page 1 of 1