perror is a c library function in c this function is used to print a descriptive error message in c.
Syntax:-
void perror(const char *str)
- str in c contain a custom message that is printed before the error message itself.
- perror function in c doesn't return any value
Example Program for perror function in c
#include<stdio.h> int main () { FILE *f; /* first rename the file */ rename("file.txt", "updatefile.txt"); /* now let's open same file */ f = fopen("file.txt", "r"); if( fp == NULL ) { perror("Error: "); return(-1); } fclose(fp); return(0); }
Output
Error: : No such file or directory