c and formatted output
char *star="*";
int space=5;
printf("%5s",star);
I want to give 5 spaces to my star s开发者_如何学运维o 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.
printf("%*s", space, star);
or
printf( "%*.*s", space, space, star);
then you will always print max. 5 chars.
hth
Mario
精彩评论