perror
suggest changeTo print a user-readable error message to stderr, call perror from <stdio.h>.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
FILE *fout;
const char *path = argc > 1 ? argv[1] : "output.txt";
if ((fout = fopen(path, "w")) == NULL) {
perror("fopen: Could not open file for writing");
return EXIT_FAILURE;
}
if (fclose(fout) == EOF) {
perror("fclose");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
This will print an error message concerning the current value of errno.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents