I would like to modify the function printf to a new function printf2 that simply prepends the message to be printed with Hello.
I could do
void printf2(char message[]) {
printf("Hello ");
printf(message);
}
The problem is that I cannot pass the extra arguments for cases when message has %d, %c, etc.
How can I have printf2 accept as many parameters printf can, and pass them on to printf?
The comment above points you in the right direction, but here is an example of how to prepend your tag (Hello).
Notes:
I have used the s and n version of printf to format a new string that shouldn’t overflow my temp buffer, and *MAX_MSG_SIZE* is assumed to be defined appropriately elsewhere.