Page 128 - Programming Microcontrollers in C
P. 128

Input and Output    113

                            g,G           Uses e or f format, whichever requires least space.
                            %             No argument is converted. Print as a %
                              Additional formatting capability exists. The complete form of
                          the % command is as follows:

                   %[flags][width][.precision][modifier]type
                          where the various optional fields have the following meanings.

                          flags

                            -             Left-justify the value if there is a width field speci­
                                          fied.
                            +             Print leading + character for positive outputs

                          width
                            Width                      Precision
                            Minimum width of           The number of digits
                            print zone. Pad the        to the right of the
                            field with 0 if the        decimal point. For
                            leading width              strings, the maximum
                            specifier is 0.            number of characters.
                          Modifier

                            Modifier      Meaning

                            h	            Used with any integral type, data type is short.

                            l	            Used with any integral type, data type is long.


                            L	            Used with any floating point type, the data type is
                                          long double.

                                 This formatting approach works with strings as well as nu­
                          merical outputs. If a string output contains a field width or a precision,
                          it works much the same as a numerical output. If the field width
                          specified is not long enough to hold the output string, the specified
                          field width is ignored. The complete string is printed out. With a
                          string, precision specifies the number of output characters. If the
                          precision is smaller than the field width, the width of the output field
                          will be the precision specification. A minus sign applied to field width
   123   124   125   126   127   128   129   130   131   132   133