answersLogoWhite

0

The perror() function is used to print a user-defined error message to stderr. Consider the following:

Example:

#include

int main ()

{

FILE * pFile;

pFile=fopen ("missing.txt","rb");

if (pFile==NULL)

perror ("missing.txt");

else

fclose (pFile);

return 0;

}

Possible Output:

missing.txt: No such file or directory

We can achieve the exact same effect with a more verbose fprintf() statement, such that the following are equivalent:

perror ("Error");

fprintf (stderr, "Error: %s\n", strerror (errno));

The following are also equivalent:

perror (NULL);

fprintf (stderr, strerror (errno));

We typically use fprintf() statement when we need to print messages other than those provided by strerror and/or wish to redirect the output to a device other than stderr. But for all error messages based upon the thread-local errno, perror is more concise and reduces the chances of introducing errors through typos (such as accidently redirecting errors to stdout instead of stderr).

User Avatar

Wiki User

∙ 9y ago

What else can I help you with?

Related Questions

Why you use void res in c programming?

since, the word 'void' in C programming language means that it does not return any value to the user or calling function....this is usually used to specify a type of function...... for this reason w use 'void'in c program..


What is the function in toupper in C programming?

toupper is used to change the case of given character to upper case


What is d command for squareroot in C programming?

There are no commands in C-programming, you should use function sqrt from math.h


What is a sizeof function in C programming?

Sizeof is an example.


Is combination a library function in c language of programming?

No.


What is put pixel?

The putpixel function is a specific function that is used in C++ programming. This command function is supposed to do point plotting via color definition of its specific points.


What is the C language used for?

Programming.


What is the difference between a precondition and postcondition in C programming?

In C programming, a precondition is a condition that must be true before a function is called, while a postcondition is a condition that is guaranteed to be true after the function has been executed.


What is a C compiler as used in C programming?

In C programming, C compiler is user to translate C source into C object module.


What is fncn in C programming?

1. identifier 2. short for function


What is the function of square root in C programming?

it is sqrt in header math.h


What is the approach of C programming known as?

Sequential style, or function-oriented. Which is opposed to object-oriented, as in C++.