PrintFormat() width, asterisk(*)

Back to topics list To post a new topic, please log in or register
avatar
736
honest_knave 2014.12.28 00:46
 

When specifying width, the documentation states that an integer value can be passed as a parameter: 

If an asterisk (*) is specified as width, value of int type must be indicated in the corresponding place of the list of passed parameters. It will be used for specifying width of the output value.

However, I'm unable to achieve this. Is this a bug or am I using incorrect syntax?

   printf("%s","mytext");
   printf("%10s","mytext");
   int width=10;
   printf("%*s",width,"mytext");

 

 

avatar
13009
WHRoeder 2014.12.28 03:44 #
 
Try string, width?
avatar
Moderator
3206
angevoyageur 2014.12.28 09:48 #
 
honest_knave:

When specifying width, the documentation states that an integer value can be passed as a parameter: 

If an asterisk (*) is specified as width, value ofint type must be indicated in the corresponding place of the list of passedparameters. It will be used for specifying width of the output value.

However, I'm unable to achieve this. Is this a bug or am I using incorrect syntax?

 

 

Seems like a bug, you can report it to ServiceDesk.
avatar
736
honest_knave 2014.12.28 10:48 #
 
WHRoeder:
Try string, width?
Thanks for the suggestion, but still doesn't work.
avatar
736
honest_knave 2014.12.28 10:48 #
 
angevoyageur:
Seems like a bug, you can report it to ServiceDesk.
OK, thank you.
avatar
736
honest_knave 2015.01.05 12:02 #
 

ServiceDesk has provided a workaround which doesn't use the asterisk:

   printf("%s","mytext");
   printf("%10s","mytext");
   int width=10;
   printf("%*s",width,"mytext");
   printf("%"+string(width)+"s","mytext");

 

avatar
Moderator
3206
angevoyageur 2015.01.05 15:04 #
 
honest_knave:

ServiceDesk has provided a workaround which doesn't use the asterisk:

 

lol
avatar
736
honest_knave 2015.01.06 16:39 #
 
Indeed!
Back to topics list  

To add comments, please log in or register