0

First of all, sorry if someone already asked about this question.

I did search about this first, but couldn't find one.

I used to see some people doing something like this:

if ( // a certain conditions here ) {
    error("ERROR: not bla bla bla")
}

what is error(....)? What is the difference with printf()?

Why they aren't using printf("ERROR: not bla bla bla") instead?

Thank you.

coava
  • 79
  • 3
  • 9

2 Answers2

1

As i know, c language has no function name "error". I think that is a function or a macro is coded or defined by user. To handle error in c, you can read this link. It has some different points with printf function. http://www.tutorialspoint.com/cprogramming/c_error_handling.htm

Viet
  • 553
  • 1
  • 4
  • 18
1

Take a look of standard streams, which includes stdin (for input), stdout for output, and stderr for error messages. Usually stdout and stderr are just terminal output, so there are no differences. However, the output can be redirected to a text file while all error messages are still available output.

Also have look at this question perror vs frintf(stderr..), which gives you a better idea as to why perror should be used.

Community
  • 1
  • 1
artm
  • 17,291
  • 6
  • 38
  • 54