The f_printf function writes formatted string to the file.
int f_printf ( FIL* fp, /* [IN] File object */ const TCHAR* fmt, /* [IN] Format stirng */ ... );
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.
The format control directive is a sub-set of standard library shown as follows:
%[flag][width][type]
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.
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.
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 */