EmbLogic's Blog

c programming “printf format specification”

printf format specification:

%[flag][width][.precision][modifier]<type>

meaning of fields with e.g.,:
format                                                                        output
1. flag: printf(“%7s”,”hello”);                                 spacespacehello

2. width: prinf(“%4d”,10);                                         spacespace10

3. precision: (“%.2f”,1.1412);                                                  1.41

4. modifier:

h interpreted as short used with  i,d,o,u,x
l interpreted as long used with i,d,o,u,x
L interpreted as double used with i,d,o,u,x

5. type: d,i,x,X as their usual meanings etc.

3 Responses to c programming “printf format specification”

  1. nitin sharma says:

    i couldn’t get the flag specifier. can u elaborate it more.

  2. @nitin sharama:
    the flags :” #,0,-,+, ,’,I ”

    # | Alternate
    0 | zero pad,
    - | left align,
    + | explicit + – sign,
    | space for + sign,
    ‘ | locale thousands grouping
    I | Use locale’s alt digits

  3. though i can’t understand completely understand all of them….

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>