X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/0f3b947bda5f34662a611272b9f12199e0da9aca..976db69ffa80c4d499e53f6f22c26d784fdac0a1:/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 (

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.

+

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.

@@ -47,14 +47,30 @@ int f_printf (

Description

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

-    %[flag][width][type]
+    %[flag][width][precision][size]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.
+
flag
Padding option. A - specifies left-aligned. A 0 specifies zero padded. The default setting is in right-aligned and space padded.
+
width
Minimum width of the field, 1-99 or *. If the width of generated string is less than the minimum width, rest field is padded with spaces or zeros. An * specifies the value comes from an argument in int type. The default setting is zero.
+
precision
Specifies number of fractional digits or maximum width of string, .0-.99 or .*. If the number is omitted, it is same as .0. Default setting is 6 for number and no limit for string.
+
size
Specifies size of integer argument, l(long) and ll(long long). If sizeof (long) == sizeof (int) is true (this is typical of 32-bit systems), prefix l can be omitted for long integer argument. The default size is int for integer argument and floating point argument is always assumed double as the default argument promotion.
+
type
Specifies type of the output format and the argument as shown below. The length of generated string is in assumtion of int is 32-bit. + + + + + + + + + + + +
TypeFormatArgumentLength
cCharacterint,
long,
long long
1 character.
dSigned decimal1 to 11 (20 for ll) characters.
uUnsigned decimal1 to 10 (20 for ll) characters.
oUnsigned octal1 to 11 (22 for ll) characters.
x XUnsigned hexdecimal1 to 8 (16 for ll) characters.
bUnsigned binary1 to 32 characters. Limited to lower 32 digits when ll is specified.
sStringTCHAR*As input string. Null pointer generates a null string.
fFloating point
(decimal)
double1 to 31 characters. If the number of characters exceeds 31, it writes "±OV". Not a number and infinite write "NaN" and "±INF".
e EFloating 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 (

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 */
+    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) */