On this page
perror
Prev: ferror | Up: stdio.h | Next: remove
Rel: stdio.h, stdio.h & File I/O Guide
Ref: cppreference — perror
Tags: #public #prog #c #stdlib #stdio #tier/core
Include
#include <stdio.h>
Signature & Overview
void perror(const char *s);
Prints s, a colon, and the human-readable error message for current errno to stderr.
Notes & Pitfalls
- Call immediately after a failing libc call: Any intervening function call may overwrite
errno.
Example
#include <stdio.h>
int main(void) {
FILE *f = fopen("missing_demo_xyz", "r");
if (!f) perror("open failed");
}
Linked from
Related notes
- tuts/c/stdlib/stdio/ferror Linked here; links to this page; shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/remove Linked here; links to this page; shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio Linked here; links to this page; shared tags: #c, #prog, #stdio, #stdlib
- tuts/c/stdlib/stdio_and_file_io Linked here; shared tags: #c, #prog, #stdlib
- tuts/c/stdlib/stdio/fclose shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/feof shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fflush shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fgets shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fopen shared tags: #c, #prog, #stdio, #stdlib, #tier
- tuts/c/stdlib/stdio/fprintf shared tags: #c, #prog, #stdio, #stdlib, #tier