Writes a short error message to stderr describing the current value of errno.
#include <stdio.h> void perror (const char *str);
See the description of errno in Chapter 4 for a list of possible errors.
See also strerror in this section.
#include <stdio.h> #include <stdlib.h> main(argc,argv) int argc; char *argv[]; { FILE *fp; int status; int total_recs = -1; fp = fopen(argv[1],"r"); /* Open an input file. */ if (fp == NULL) { /* * If the fopen call failed, perror prints out a diagnostic: * * "open: <error message>" * This error message provides a diagnostic explaining * the cause of the failure. * */ perror("open"); exit(1); } }