A
Arthur J. O'Dwyer
I have a situation where I want to use one of two different format
strings in a 'printf' call, depending on a flag set by the user.
One of the calls uses a field width modifier, and the other one doesn't.
So what I have at the moment is
if (UserFlag) {
printf("%*d. ", clue_width, clue_number);
}
else {
printf("%d.\t", clue_number);
}
What I'd like to have is
const char *clue_format = (UserFlag? "%*d. ": [...something...]);
printf(clue_format, clue_width, clue_number);
Problem is, I don't see any way to tell 'printf' to simply discard
its second argument. "%0.0d" doesn't work; according to the standard,
'printf' will never truncate its output, even given a zero field width.
So, can anyone think of what my [...something...] should be?
Failing that, can anyone think of a method shorter and cleaner than
the method outlined above?
Thanks,
-Arthur
strings in a 'printf' call, depending on a flag set by the user.
One of the calls uses a field width modifier, and the other one doesn't.
So what I have at the moment is
if (UserFlag) {
printf("%*d. ", clue_width, clue_number);
}
else {
printf("%d.\t", clue_number);
}
What I'd like to have is
const char *clue_format = (UserFlag? "%*d. ": [...something...]);
printf(clue_format, clue_width, clue_number);
Problem is, I don't see any way to tell 'printf' to simply discard
its second argument. "%0.0d" doesn't work; according to the standard,
'printf' will never truncate its output, even given a zero field width.
So, can anyone think of what my [...something...] should be?
Failing that, can anyone think of a method shorter and cleaner than
the method outlined above?
Thanks,
-Arthur