Prints an error message to stderr
.
Include
<stdio.h>
Prototype
void perror(const char * s);
Argument
s |
Return Value
None.
Remarks
The string s
is printed followed by a colon and a space.
Then, an error message based on errno
is printed followed by an newline.
Example
See the notes at the beginning of this chapter or section for
information on using printf()
or scanf()
(and other functions reading and writing the stdin
or
stdout
streams) in the example code.
#include <math.h>
#include <stdio.h>
#include <errno.h>
int main(void)
{
double x,y;
errno = 0;
x = -2.0;
y = acos (x);
if (errno)
perror("Error");
printf("The arccosine of %f is %f\n", x, y);
}
Example Output
Error: Domain error
The arccosine of -2.000000 is nan