0

Why we used . while printing the string.

    printf("%*.*s",10,7,str);

This is the actual program. how the printf statement preforms the operation in detailed explanation.

    #include<stdio.h>
    int main()
    { 
    char *str="c-pointer";
    printf("%*.*s",10,7,str); 
    return 0; 
    }
user120242
  • 14,918
  • 3
  • 38
  • 52

2 Answers2

0
printf("%*.*s",10,7,str); 

equal to

printf("%10.7s",str);

You tell to printf to print minimum 10 Letter and first 7 characters in str, so

"   c-point"
 ^^^^^^^^^^

The character to fill is space and default justification is right.

And you can change justify to left by

printf("%-10.7s",str);

it will print

"c-point   "

and you can not add 0 to %s but you can do this in numeric conversions and you can not use both - and 0 in numeric conversions also because - will override 0.

srilakshmikanthanp
  • 2,231
  • 1
  • 8
  • 25
0

The .7 is a precision

Read no more the 7 characters from str.


The 10 is a minimum width

Print at least 10 characters, pad if needed.

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256