The function perror () in C
The function void perror (const char * str) in the C Library standard prints a message describing the error to stderr. First, the printed string str is followed by a colon and then a space.
The function void perror (const char * str) in the C Library standard prints a message describing the error to stderr. First, the printed string str is followed by a colon and then a space.
Declare the perror () function in C
Here is the declaration for the perror () function in C:
void perror ( const char * str )
Parameters
str - This is the string containing a Custom message to be printed before the error message.
Returns the value
This function does not return any values.
For example
The following C program illustrates the usage of the perror () function in C:
#include int main () { FILE * fp ; /* Doi ten file */ rename ( "baitapc.txt" , "newbaitapc.txt" ); /* bay gio thu co gang mo baitapc.txt */ fp = fopen ( "baitapc.txt" , "r" ); if ( fp == NULL ) { perror ( "Error: " ); return (- 1 ); } fclose ( fp ); return ( 0 ); }
Compiling and running the above C program will result: (because we're trying to open a file that doesn't exist)
According to Tutorialspoint
Previous lesson: Function ungetc () in C
Next lesson: stdlib.h in C
You should read it
Maybe you are interested
The whole scene of meteorites hitting the Earth during the past 33 years, why can't we feel it? Discovered mysterious signals emanating from a star right next to the Solar System, possibly of aliens NASA reveals its latest snapshot of the Martian surface with a resolution of 1.8 billion pixels Found the second planet of Proxima Centauri, the star closest to the sun 7 most modern astronaut ships on the planet Is Proxima b our 'neighbor' planet?