0
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.

1
  • 1
    BTW- I believe the first line should read const char *star="*". Minor issue, but string literals are constant Commented Apr 27, 2011 at 6:22

1 Answer 1

3
printf("%*s", space, star); 

or

printf( "%*.*s", space, space, star); 

then you will always print max. 5 chars.

hth

Mario

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.