What does printf("%*.*s",int,int,char *) mean in c? -


this question has answer here:

i got code snippet in there statement

printf("%*.*s"); 

what %*.*s mean?

the code is

char *c="**********"; int i,n=4; for(i=1;i<=n;i++) { printf("%*.*s\n",i,i,c); } 

output is:

* ** *** **** 

read spec of printf:

%[flags][width][.precision][length]specifier

s string of characters

* width not specified in format string, additional integer value argument preceding argument has formatted.

for strings width minimum number of characters printed (padding may added).

.* precision not specified in format string, additional integer value argument preceding argument has formatted.

for strings precission maximum number of characters printed.

your program not passing required optional arguments (witdh, precission, string printed). behavior undefined (likely crash).


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -