c - Understanding printf function with * format -


char **w = c->u.word; printf ("%*s%s", indent, "", *w); 

ok, currently, *w holds "true" string value.
, have no problem accessing it.
indent integer value, 2.

first, don't understand how printf function works in case. looks has 4 arguments. second, expected output 'true', got nothing. why behave this?

the asterisk (*) means can define variable field width. so

"%*s%s" 

means have string variable field width (the length of field passed integer before string printf). followed string printed no padding.

your parameters are:

indent, "", *w 

in format, indent corresponds asterisk (*), "" corresponds s in %*s, , *w corresponds %s. print zero-length string field width of indent followed string *w points to. in other words, you'll indent spaces in front of string *w in output.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -