Why doesn't printf allow you to specifiy multiple format strings? [closed]

How would printf() know where the formatting strings ended and the actual values began? You’re not including any such information, which is the entire point of the formatting string: describing the variable number of arguments so the code inside printf() knows how many arguments to process.

And in what way is that better than

printf("%d%d", 2, 4);

?

Also, the printed result ("24", without newline) would be pretty hard to interpret in any way, so you’d might as well add spacing, which will help make the formatting string more readable:

printf("%d %d", 2, 4);

That will print "2 4" (again, without newline).

Note that in C, there’s no way for a variable-arguments function (printf() in this case) to somehow determine the amount (or types!) of its argument(s). It has to know, or be able to compute on its own based on some of the arguments (or some other state).

Also, if wanted to print "%s", I wonder how you imagine

printf("%s", "%s");

should work?

Leave a Comment