fprintf( stderr, "%*s %s: \n", 6*level, "Target Entity ID: ",
get_entity_id( child, level+1 ) );
Note: strlen("Target Entity ID: ") is 18.
produces no leading blanks (spaces), while:
fprintf( stderr, "%*s %s name: %s: \n", 6*level, "Node: ", child->name,
attr );
produces the expected/require leading blanks (spaces).
Note: strlen("Node: ") is 6.
Next, we have:
I checked the value of 'level' in the first fprintf and it was what I
expected (3).
Assuming "level" has type int (or promotes to type int), 6*level will
be 6*3, i.e., the "int" value 18.
printf("[%18s]", "123456789012345678");
printf("[%18s]", "123456");
should cause the square brackets to line up, because the first
string is 18 characters long and printed in an 18 character field,
while the second string is 6 characters long and printed in an 18
character field. The field width tells printf() to pad (with
spaces, in this case) as needed to make sure the output is at least
that long. Since 18 minus 18 is zero, the first printf() requires
no extra padding characters.
(If "level" has type long, or double, or similar, all bets are off,
because "%*s" needs one (int) and one (char *). I suspect this is
not a problem, though.)