0

I need to print to a file a variety of format strings. I will have integers associated with each string, the same number of integers as format specifiers in each string. Most strings will not have the same number of format specifiers/integers.

So given a format string along the lines of blah blah blah %d something else blah %hd blah blah blah %02hd blah %d and an argument list containing four integers that need to go in this statement, will vsprintf work its way through the argument list and format statement in parallel, placing the first list item at the first specifier, second item at the second specifier, so on and so forth. Or will it go through the list placing all items at the first specifier?

In other words are the following two statements equivalent?

sprintf(buffer,"blah blah blah %d something else blah %hd blah blah blah %02hd blah %d",a1,a2,a3,a4)

vsprintf(buffer,"blah blah blah %d something else blah %hd blah blah blah %02hd blah %d", args)

in vsprintf args would be a va_list. va_list args;.

4
  • It might help clarify discussion if you show how you are (or would) build the args list for the vsprintf call. Commented May 15, 2014 at 18:59
  • I am still working through how exactly I am going to fill the va_list. Commented May 15, 2014 at 19:27
  • Those are equivalent, so long as the args was created by doing va_start correctly inside a function that was called with a1,a2,a3,a4 corresponding to the ellipsis. If you're thinking about building your own va_list, don't. Commented May 15, 2014 at 23:40
  • Is it even remotely possible to have a vector, one the changes size, correspond to that ellipsis? Commented May 16, 2014 at 13:49

1 Answer 1

1

will vsprintf work its way through the argument list and format statement in parallel, placing the first list item at the first specifier, second item at the second specifier, [etc.]

Yes, that is the result it will produce.

Or will it go through the list placing all items at the first specifier?

No. vsprintf would not be a useful function if it did that.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.