You Could Well Do This First Make a char
array , Containing Number Of Maximum Stars that will be asked to print.
char stars[] = "***************************************";
Then Ask User Input for number of stars they want to print.
int a;
printf("Enter Number of Stars You Want To Print : ");
scanf("%d" , &a);
Then You print it using
printf("%.*s\n" , a , stars);
What is basically happening is that you are setting variable width by using %.*s
, here *
is taking a
, for example if a = 5
then it turns out to be %.5s
and then it print first 5
characters of string.
The catch here is you should know maximum number of stars that you would be asked to print so that you can initialize the character array according to your need.
Please See These Question To Know More How to print only certain parts of a string? and Set variable text column width in printf .
If someone down vote the answer , please let me know in comment section why you did so , so that i can improve on it.
0
solved I want to print a name inputted by the user and some stars(inputted too) EXACTLY before and after the name [closed]