Hello,
C99
gcc 4.4.3
I want to report some error messages to the user of my program. I have found that using Variadic function is the most scalable method to use, but I am not sure how to put it together, this is what I have so far.
Many thanks for any suggestions,
Code:
typedef enum
{
DEV_FAILED, /* Device failed to open */
EX_FAILED, /* Cannot open library */
HOST_INFO_ERR, /* Cannot get host information */
} report_msg;
Code:
#include <stdarg.h>
void report_error(FILE *out, const char *fmt, ...)
{
va_list ap;
va_start(ap_fmt);
vfprintf(out, fmt, ap);
va_end(ap);
}
Code:
my_error(stderr,
"%s: Invalid range of %ld near line %d", __func__, range, __LINE__);