开发者

c and formatted output

开发者 https://www.devze.com 2023-03-01 11:32 出处:网络
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 |*|
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

精彩评论

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