开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜