How do I use multiple precisions in printf()?

Posted by Tommy on Stack Overflow See other posts from Stack Overflow or by Tommy
Published on 2010-04-26T18:40:59Z Indexed on 2010/04/26 20:33 UTC
Read the original article Hit count: 154

Filed under:
|
|
|
|

Looking at the information under the heading "Precision can be omitted or be any of:".

The example: printf("%.*s", 3, "abcdef"); works, outputting:abc (truncating the rest of the string.)

Now, I would like to have a string with multiple parameters formatted (truncated):

printf("%.*s, %.*s", 3, 3, "abcdef", "xyz123");

but the program crashes.

What is the correct syntax?

Thank You.

© Stack Overflow or respective owner

Related posts about c

    Related posts about formatting