Reputation: 41
char *star="*";
int space=5;
printf("%5s",star);
I want to give 5 spaces to my star so it should look on command line like | *|
But the space quantity must be a variable so users can decide.
I tried printf("%%ds",i,s);
not worked. Thank you.
Upvotes: 0
Views: 101
Reputation: 4859
printf("%*s", space, star);
or
printf( "%*.*s", space, space, star);
then you will always print max. 5 chars.
hth
Mario
Upvotes: 3