I want to implement a function Myprintf() that takes arguments like printf().
Now I am doing this by:
sprintf(demoString, "Num=%d String=%s", num, str);
Myprintf(demoString);
I want to replace this function call as:
Myprintf("Num=%d String=%s", num, str);
How is this possible?
It isn’t clear from your question exactly how the output is done; your existing
Myprintf()presumably outputs it somewhere, maybe withfprintf(). If that’s the case, you might write instead:If you don’t want to use the return value, declare the function as
voidand don’t bother with the variablerc.This is a fairly common pattern for ‘
printf()cover functions’.