Dear all,
I use perror in order to print an error message to the standar error. For example
if a C program is called without its two necessary command line parameters
then :
if (argc != 3)
{
perror("use: ./myProgram <source file> <target file>\n");
return 1;
}
Now the problem is whenever this error message is printed, I have this:
use: ./myProgram <source file> <target file>\n
: Success
What I don't understand is why there is a second line: ":Success"??
Is there a way to remove it? as I want to print an error message, it doesn't
really make sense to print Success.
Thanks in advance,
Kind Regards,
pludi
August 15, 2009, 8:23am
2
Did you read up on what perror() does?
The perror() function finds the error message corresponding to the current value of the global variable errno and writes it, followed by a newline, to the standard error file descriptor. If the argument s is non-NULL and does not point to the null character, this string is prepended to the message string and separated from it by a colon and space (": "); otherwise, only the error message string is printed.
Since neither you nor any other function set errno, it's probably defaulted to zero, which means success.
If you want to output any error messages that stem from logical errors, I'd suggest writing them to stderr via fprintf.
pludi:
Did you read up on what perror() does?
Since neither you nor any other function set errno, it's probably defaulted to zero, which means success.
If you want to output any error messages that stem from logical errors, I'd suggest writing them to stderr via fprintf.
Dear pludi
Thank you very much for your help. Your solution solved my problem.
if (argc != 3)
{
fprintf(stderr, "use: ./myProgram <source file> <target file>\n");
return 1;
}
And it prints only the error message.
Thanks a lot for your help.
Kind Regards,