Hello!

The task is asked to display the name, in the field width of three characters longer than the length of the name. Programming language - si.

I can not understand how to implement it.

I tried:

printf("%",strlen(name)+3, "s\n", name); 

Did more different ways - not a ride. Please explain how to implement.

Thank!

PS You can use only printf, scanf.



    2 answers 2

    The width of the output field is set by an asterisk. Those. Formally, you can write printf ("% * s", strlen (name) +3, name);

    The name value here will be displayed with alignment to the right. Align the left border as follows: printf ("% - * s", strlen (name) +3, name);

    • That is, in place of the asterisk appears the number I need? And why is this happening, I just do not understand? - VladislavMSK
    • Because this is how printf formatted output works. Read the specification. The number will not appear, but printf, having encountered asterix in the specifier of field width, will understand that the next argument in the list is the size and considers it from the stack - renegator

    Just three spaces behind can not be displayed in the format string?

     printf("%s \n", name) 
    • So not interesting :). - VladislavMSK