## f_printf

The f_printf function writes formatted string to the file.

    int f_printf (
      FIL* fp,          /* [IN] File object */
      const TCHAR* fmt, /* [IN] Format stirng */
      ...
    );

#### Parameters

fp
  Pointer to the open file object structure.
fmt
  Pointer to the null `'\0'` terminated format string. The terminator character will not be output.
...
  Optional arguments...

#### Return Values

When the string was written successfuly, it returns number of character encoding units written to the file. When the function failed due to disk full or any error, an `EOF (-1)` will be returned.

#### Description

The format control directive is a sub-set of standard library shown as follows:

        %[flag][width][type]

flag
  Padding options. A `-` specifies left justified. A `0` specifies zero padded.
width
  Minimum width of the field, `1-99` or `*`. If the width of generated string is less than the specified value, rest field is padded with white spaces or zeros. An `*` specifies the value comes from an argument in int type.
type
  `c s d u o x b` and prefix `l` specify type of the argument, character, string, signed integer in decimal, unsigned integer in decimal, unsigned integer in octal, unsigned integer in hexdecimal and unsigned integer in binary respectively. If `sizeof (long)` is greater than `sizeof (int)` (this is typical of 8/16-bit systems), a prefix `l` needs to be explicitly specified for long integer argument. These characters except for `x` are case insensitive.

When FatFs is configured for Unicode API (`FF_LFN_UNICODE >= 1`), character encoding on the string fuctions, `f_putc`, `f_puts`, `f_printf` and `f_gets` function, is also switched to Unicode. The Unicode characters in multiple encoding unit, such as surrogate pair and multi-byte sequence, should not be divided into two function calls, or the character will be lost. The character encoding on the file to be written via this function is selected by `FF_STRF_ENCODE`. The characters with wrong encoding or invalid for the output encoding will be lost.

#### QuickInfo

This is a wrapper function of `f_write` function. Available when `FF_FS_READONLY == 0` and `FF_USE_STRFUNC >= 1`. When `FF_USE_STRFUNC == 2`, `'\n'`s in the generated string are written as `'\r'+'\n'` each.

#### Example

        f_printf(&fil, "%d", 1234);            /* "1234" */
        f_printf(&fil, "%6d,%3d%%", -200, 5);  /* "  -200,  5%" */
        f_printf(&fil, "%ld", 12345L);         /* "12345" */
        f_printf(&fil, "%06d", 25);            /* "000025" */
        f_printf(&fil, "%06d", -25);           /* "000-25" */
        f_printf(&fil, "%*d", 5, 100);         /* "  100" */
        f_printf(&fil, "%-6d", 25);            /* "25    " */
        f_printf(&fil, "%u", -1);              /* "65535" or "4294967295" */
        f_printf(&fil, "%04x", 0xAB3);         /* "0ab3" */
        f_printf(&fil, "%08lX", 0x123ABCL);    /* "00123ABC" */
        f_printf(&fil, "%04o", 255);           /* "0377" */
        f_printf(&fil, "%016b", 0x550F);       /* "0101010100001111" */
        f_printf(&fil, "%s", "String");        /* "String" */
        f_printf(&fil, "%8s", "abc");          /* "     abc" */
        f_printf(&fil, "%-8s", "abc");         /* "abc     " */
        f_printf(&fil, "%c", 'a');             /* "a" */
        f_printf(&fil, "%f", 10.0);            /* f_printf lacks floating point support */

#### See Also

`f_open, f_putc, f_puts, f_gets, f_close, FIL`

Return