M
Mark
Hi all
My c is a bit rusty and my brain is dead!
Can anyone tell me why the following trys to print when I call
pferror(E1); ...
#include <stdio.h>
#include <stdarg.h>
#define UE 0
#define E1 1
#define E2 2
#define E3 3
#define E4 4
char *error_msg[] = {
"Undefined error",
"Error msg 1",
"Error msg 2",
"Error msg 3",
"Error msg 4",
};
/* Print formatted error */
void pferror (int, ...);
int
main ()
{
pferror(E1);
pferror(E2, "Msg (E2)");
pferror(E3, "Msg (E3) (%d)", 111);
pferror(E4, "Msg (E4) (%d)(%s)", 222, "Three");
return 0;
}
void
pferror (int error, ...)
{
va_list args;
char *fmt;
fprintf(stderr, "Error: %s ", error_msg[error]);
va_start(args, error);
fmt = va_arg(args, char *);
if(fmt)
vfprintf(stderr, fmt, args);
va_end(args);
fprintf(stderr, "\n");
}
My c is a bit rusty and my brain is dead!
Can anyone tell me why the following trys to print when I call
pferror(E1); ...
#include <stdio.h>
#include <stdarg.h>
#define UE 0
#define E1 1
#define E2 2
#define E3 3
#define E4 4
char *error_msg[] = {
"Undefined error",
"Error msg 1",
"Error msg 2",
"Error msg 3",
"Error msg 4",
};
/* Print formatted error */
void pferror (int, ...);
int
main ()
{
pferror(E1);
pferror(E2, "Msg (E2)");
pferror(E3, "Msg (E3) (%d)", 111);
pferror(E4, "Msg (E4) (%d)(%s)", 222, "Three");
return 0;
}
void
pferror (int error, ...)
{
va_list args;
char *fmt;
fprintf(stderr, "Error: %s ", error_msg[error]);
va_start(args, error);
fmt = va_arg(args, char *);
if(fmt)
vfprintf(stderr, fmt, args);
va_end(args);
fprintf(stderr, "\n");
}