Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ 3.0r4 - <b>fprintf</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
fprintf

Usage

   #include <stdio.h>
   int fprintf(FILE *fp,const char *format,...);

   ANSI

Description

   fprintf, printf and sprintf are the formatted print routines. fprintf
   writes its characters to the file stream fp.

   Arguments are interpreted according to the zero terminated format string.
   The format string is a sequence of characters with embedded conversion
   commands. Characters that are not part of the conversion command are
   output. Conversion commands consist of:


       '%'{flag}[field_width]['.' precision]['l' or 'L']conversion_char

   where a % always signifies the beginning of a conversion command. To
   print a (%) use (%%).

Flag Characters

   -                Means left justify the conversion.

   +                Means that signed conversions always start with a + or -.

   Space            means that for positive conversions, the conversion will
                    start with a space. The + flag overrides the space flag.

   #                For x or X conversions, if the result is non-zero then a
                    0x or 0X will be added to the front of it. For o
                    conversions, a leading 0 will be added. For floating
                    conversions (e, E, f, g, G), a decimal point will always
                    appear. If it is g or G, then trailing 0 s will not be

                    truncated.

   field_width

   Decimal integer controlling the minimum number of characters printed. If
   the actual number of characters is less than the field_width, it is
   padded with blanks. If the field_width digit string begins with a 0, it
   is padded with a 0.

   If the field_width is the character *, the actual field_width value is
   taken from the next int arg. If the field_width is negative, it is
   treated as if the - flag were given and the absolute value of the
   field_width is used. If there are more characters than allowed for by the
   field_width, then the width is expanded appropriately.

   precision

   .        Followed by a digit string specifying the precision of the
            conversion.If no digits appear after the ".", then the
            precision is taken as 0. For integral conversions, this

            is the minimum number of digits. For g and G, the
            precision gives the maximum number of significant
            digits. For e, E, and f, it is the number of digits
            appearing after the decimal point. For s, it is the
            maximum number of characters in a string. If the
            precision starts with a 0, then the conversion is 0
            padded.

   l        Lower case L. If a o, u, x, X, i, d  or b conversion
            character is specified, then the argument is taken to be
            a long, except for a p conversion, when the argument is
            taken to be a far pointer. For all other conversion
            characters, it is ignored.

   L        This flag is ignored.

   conversion_char
            One of the characters b,d, i, o, u, x, X, f, e, E, g,
            G, c, s, p, n, %.
            Other characters cause undefined behavior.

   b,d,i,o,u,x,X
            The argument is an integer and it is converted to a
            string of digits according to the conversion character.
            b is unsigned binary, o is unsigned octal, u is unsigned
            decimal, x and X are unsigned hex, i and d are signed
            decimal. For x, lower-case hex letters are used. For X,
            upper-case ones are used. If no precision is specified,
            it defaults to one. If there are fewer digits than
            precision, leading spaces are placed before the digits.
            If the argument is 0 and the precision is 0, no
            characters are printed.

   c        The least significant byte of the integer argument is
            printed as a character.

   e,E      The argument is a double. It is printed using scientifc
            notation, ([-]d.dddddde+- dd). There is one digit before
            the decimal point and precision digits after. The
            precision defaults to 6. If the precision is 0, the
            decimal point is not written. E is used for the exponent

            instead of e if the E conversion character was
            specified. A minimum of two digits will appear in the
            exponent.

   f        The argument is a double. It is converted to a decimal
            string of the form [-]dd.dddd. The number of digits
            after the decimal point is given by the precision, which
            defaults to 6. If the precision is 0, no fractional
            digits or decimal points appear.

   g,G      The argument is a double. It is printed using f or e (or E
            if G was specified) format, depending on the value of
            the argument. e will be used if the exponent is <-3 or >
            the precision. The precision gives the number of
            significant digits; it defaults to 6. The decimal point
            appears if followed by a digit; trailing 0 s are
            truncated.

   n        The argument is a pointer to an int, into which is written
            the number of characters printed so far. No characters
            are generated or converted by this.

   p        The argument is a pointer which is printed as
            segment:offset for far pointers or as xxxx for near
            pointers.

   s        The argument is a pointer to a string. The characters are
            printed until a 0 is encountered or the number of
            characters specified in precision are printed. The
            terminating 0 is not printed. The precision defaults to
            32767.

   %        The % character is printed.

Example 

   #include <stdio.h>
   #include <stdlib.h>

   int main()
   {
       char *msg = "Integer formats are: ";
       int in = 10;

       fprintf(stdout,
   "%sHex: 0%x Dec: %d Oct: %o Bin: %b\n",
   msg,in,in,in,in);
       return EXIT_SUCCESS;
   }

Return Value

   Returns the number of characters written or a negative value on error.

See Also

   printf, scanf, sprintf, vprintf, vsprintf, vfprintf




See Also: printf scanf sprintf vprintf

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson