X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/0f3b947bda5f34662a611272b9f12199e0da9aca..18d57acbf4ccd7220e59fe1f2ac1556837c5da83:/fatfs/documents/doc/printf.html diff --git a/fatfs/documents/doc/printf.html b/fatfs/documents/doc/printf.html index 82be70c..eb64e8d 100644 --- a/fatfs/documents/doc/printf.html +++ b/fatfs/documents/doc/printf.html @@ -39,7 +39,7 @@ int f_printf (
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.
+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 an error, a negative value will be returned.
The format control directive is a sub-set of standard library shown as follows:
- %[flag][width][type] + %[flag][width][precision][size]type
Type | Format | Argument | Length |
---|---|---|---|
c | Character | int, long, long long | 1 character. |
d | Signed decimal | 1 to 11 (20 for ll) characters. | |
u | Unsigned decimal | 1 to 10 (20 for ll) characters. | |
o | Unsigned octal | 1 to 11 (22 for ll) characters. | |
x X | Unsigned hexdecimal | 1 to 8 (16 for ll) characters. | |
b | Unsigned binary | 1 to 32 characters. Limited to lower 32 digits when ll is specified. | |
s | String | TCHAR* | As input string. Null pointer generates a null string. |
f | Floating point (decimal) | double | 1 to 31 characters. If the number of characters exceeds 31, it writes "±OV". Not a number and infinite write "NaN" and "±INF". |
e E | Floating point (e notation) | 4 to 31 characters. If the number of characters exceeds 31 or exponent exceeds +99, it writes "±OV". |
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.
+If sprintf is used in the project and code conversion is not needed, f_write with sprintf will be efficient in code size and performance rather than f_printf.
@@ -67,23 +83,24 @@ int f_printf (- 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 */ + f_printf(fp, "%d", 1234); /* "1234" */ + f_printf(fp, "%6d,%3d%%", -200, 5); /* " -200, 5%" */ + f_printf(fp, "%-6u", 100); /* "100 " */ + f_printf(fp, "%ld", 12345678); /* "12345678" */ + f_printf(fp, "%llu", 0x100000000); /* "4294967296" (FF_PRINT_LLI) */ + f_printf(fp, "%lld", -1LL); /* "-1" (FF_PRINT_LLI) */ + f_printf(fp, "%04x", 0xA3); /* "00a3" */ + f_printf(fp, "%08lX", 0x123ABC); /* "00123ABC" */ + f_printf(fp, "%016b", 0x550F); /* "0101010100001111" */ + f_printf(fp, "%*d", 6, 100); /* " 100" */ + f_printf(fp, "%s", "abcdefg"); /* "abcdefg" */ + f_printf(fp, "%5s", "abc"); /* " abc" */ + f_printf(fp, "%-5s", "abc"); /* "abc " */ + f_printf(fp, "%.5s", "abcdefg"); /* "abcde" */ + f_printf(fp, "%-5.2s", "abcdefg"); /* "ab " */ + f_printf(fp, "%c", 'a'); /* "a" */ + f_printf(fp, "%12f", 10.0); /* " 10.000000" (FF_PRINT_FLOAT) */ + f_printf(fp, "%.4E", 123.45678); /* "1.2346E+02" (FF_PRINT_FLOAT) */