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
Discover more
run program C parameters in C Function ftell () in CShare by
Isabella Humphrey
Update 25 May 2019
You should read it
- Function vfprintf () in C
- Function fprintf () in C
- Function fputc () in C
- Function tmpnam () in C
- The function gets () in C
- The Quiet Details That Make a Sports Betting Platform Feel Reliable
- Instructions on creating toy set images with ChatGPT AI
- How are AI agents changing the journalism industry?
- stdlib.h in C
- Atof () function in C
- The function atoi () in C