Thanks prelude. I've tested both your methods with slight mod. Here's the working code if anyone is interested.
typedef enum errors{
DEVICE_ERROR,
DEVICE_NOT_FOUND,
UNKNOWN_DEVICE,
DEVICE_NOT_READY,
STATUS_OK
}STATUS_T;
const char *error_msgs[] = {
"Error: Device error",
"Error: Device_not_found",
"Error: Unknown device",
"Error: Device not ready",
"Error: Status OK"
};
void report_status (STATUS_T e_code)
{
printf ("%s\n", error_msgs[e_code] );
}
void report_status_with_args ( char *fmt, ... )
{
va_list args;
va_start ( args, fmt );
vprintf (fmt, args );
va_end ( args );
}
STATUS_T which_error()
{
STATUS_T this_error = UNKNOWN_DEVICE;
return this_error;
}
STATUS_T find_device(char *devStr, char *rtrnStr)
{
char *devName = "FLOPPY";
STATUS_T status = STATUS_OK;
if (strcmp(devStr, devName)==0)
{
strcpy(rtrnStr,devStr);
}
else
{
strcpy(rtrnStr,devName);
status = UNKNOWN_DEVICE;
}
return status;
}
int main (void)
{
STATUS_T error = STATUS_OK;
char *device = "SCANNER";
char *retDev = malloc(sizeof(char *));
error = which_error();
report_status(error);
error = find_device(device, retDev);
report_status_with_args("\n %s. Expected: %s. Got: %s\n", error_msgs[error], device, retDev);
return 0;
}