Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c
error handling

What is perror in C?

Behzad Ahmad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The perror() function displays the description of the error that corresponds to the error code stored in the system variable errno.

errno is a system variable that holds the error code referring to the error condition. A call to a library function produces this error condition.

Syntax

Parameter

  • str: The pointer to a null-terminated string. This string should contain an explanatory message about the error.

Code

The perror() function shows the output in the following order:

  • The contents of the string pointed to by specified pointer i.e., str
  • Followed by “:”
  • Then appends the error message corresponding to the error code in variable errno
main.c
file.txt
Hello

RELATED TAGS

c
error handling

CONTRIBUTOR

Behzad Ahmad
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring