This wiki is being migrated to http://www.github.com/z88dk/z88dk/wiki

 

Differences

This shows you the differences between two versions of the page.

libnew:stdio [2015/08/01 05:10]
aralbrec
libnew:stdio [2016/05/20 03:37] (current)
aralbrec
Line 76: Line 76:
  * Blanks, tabs or other whitespace which cause any leading whitespace to be consumed from //stream//   * Blanks, tabs or other whitespace which cause any leading whitespace to be consumed from //stream//
  * Ordinary characters (not %) which are expected to match the subsequent characters read from //stream//   * Ordinary characters (not %) which are expected to match the subsequent characters read from //stream//
-  * Conversion specifications consisting of a %, an optional assignment suppression character *, an optional number indicating a maximum field width (>0), and a conversion character.+  * Conversion specifications consisting of a %, an optional assignment suppression character *, an optional number indicating a maximum field width (>0), an optional length modifier, and a conversion character.
-A conversion specification determines how the next bytes on the stream are interpretted.  Normally the result is placed in the variable pointed to by the next argument in the argument list.  If assignment suppression is indicated by *, as in %*s, the input field is read from the stream but no assignment is made.  An input field is defined as a string of non-whitespace characters; it extends until the next whitespace character or until the field width, if specified, is exhausted.  This implies that //scanf// will read across line boundaries to find its input since newlines are considered whitespace.  +A conversion specification determines how the next bytes on the stream are interpreted.  Normally the result is placed in the variable pointed to by the next argument in the argument list.  If assignment suppression is indicated by *, as in %*s, the input field is read from the stream but no assignment is made.  An input field is defined as a string of non-whitespace characters; it extends until the next whitespace character or until the field width, if specified, is exhausted.  This implies that //scanf// will read across line boundaries to find its input since newlines are considered whitespace. 
-The conversion character indicates how the input field is interpretted.  The conversion characters are listed below:+The following length modifiers are accepted: hh, h, l, ll, j, z, t, L but only "l" has meaning for converters "Bdinopux" and (sdcc only) "ll" for converters "dioux". 
 + 
 +The conversion character indicates how the input field is interpreted.  The conversion characters are listed below:
^  CHARACTER  ^  STREAM CHARACTERS          ^ASSIGNED TO  ^ ^  CHARACTER  ^  STREAM CHARACTERS          ^ASSIGNED TO  ^
Line 93: Line 95:
|  s          |  characters <sup>8</sup>    |char *      | |  s          |  characters <sup>8</sup>    |char *      |
|  [..]      |  characters <sup>5</sup>    |char *      | |  [..]      |  characters <sup>5</sup>    |char *      |
-|  [//carat//..]    |  characters <sup>6</sup>  |char *    |+|  [%%^%%..]    |  characters <sup>6</sup>  |char *    |
|  u          |  unsigned decimal number    |uint16_t *  | |  u          |  unsigned decimal number    |uint16_t *  |
|  x          |  hexadecimal number <sup>3</sup>  |uint16_t *  | |  x          |  hexadecimal number <sup>3</sup>  |uint16_t *  |
Line 105: Line 107:
|  lu        |  unsigned decimal number    |uint32_t *  | |  lu        |  unsigned decimal number    |uint32_t *  |
|  lx        |  hexadecimal number <sup>3</sup>  |uint32_t *  | |  lx        |  hexadecimal number <sup>3</sup>  |uint32_t *  |
 +^  ^  ^  ^
 +|  lld        |  decimal number              |int64_t *    |
 +|  lli        |  number <sup>1</sup>        |int64_t *    |
 +|  llo        |  octal number <sup>2</sup>  |uint64_t *  |
 +|  llu        |  unsigned decimal number    |uint64_t *  |
 +|  llx        |  hexadecimal number <sup>3</sup>  |uint64_t *  |
^  ^  ^  ^ ^  ^  ^  ^
|  %          |  match % from //stream//    |no assignment made  | |  %          |  match % from //stream//    |no assignment made  |
Line 122: Line 130:
<sup>**8**</sup> leading whitespace is skipped then characters are read until the next whitespace char <sup>**8**</sup> leading whitespace is skipped then characters are read until the next whitespace char
-**NOTE:** Some or all of these converters may be disabled by the target's library config file.  Floating point converters "aefg" have not been added yet but string to float conversion can also be done with [[strtod]] and [[atof]].+**NOTE:** Some or all of these converters may be disabled by the target's library config file.  Floating point converters "aefg" have not been added yet but string to float conversion can also be done with [[strtod]] and [[atof]].  One method to read floats would be to first scan them as a string using %[ and then using one of the aforementioned functions to convert the string to a float.
If an error occurs, the carry flag is set and //errno// will be set to: If an error occurs, the carry flag is set and //errno// will be set to:
-  * [EACCES] the stream is not open for input+  * [EACCES] the stream is not open for input or the stream is in an error state 
 +  * [EINVAL] unknown conversion specifier or error during stream conversion 
 +  * [ERANGE] width out of range
-The device driver may set other errors.  //errno// is not set if there is a character mismatch or a conversion could not be performed because of invalid input on the stream.+The device driver may set other errors.  //errno// is not set if there is a character mismatch with the format string.
===== int scanf(const char *format, ...) ===== ===== int scanf(const char *format, ...) =====
Line 164: Line 174:
If the width or precision is '*', their value is taken from an int argument in the parameter list.  A negative field width argument is taken as a '-' flag followed by a positive field width. A negative precision argument is taken as if the precision were omitted. If the width or precision is '*', their value is taken from an int argument in the parameter list.  A negative field width argument is taken as a '-' flag followed by a positive field width. A negative precision argument is taken as if the precision were omitted.
-  * a length modifier.  hh, h, l, ll, j, z, t, L are all accepted but only 'l' has meaning, indicating a following BdiouxX conversion specifier applies to a long or unsigned long argument.+  * a length modifier.  hh, h, l, ll, j, z, t, L are all accepted but only 'l' has meaning for converters "BdiouxX" and (sdcc only) 'll' has meaning for "diouxX".
Finally, the conversion characters and their meanings are shown below.  If the character after % is not listed below, EINVAL is returned. Finally, the conversion characters and their meanings are shown below.  If the character after % is not listed below, EINVAL is returned.
Line 186: Line 196:
|  lx,lX      |  uint32_t      |unsigned hexadecimal, X uses capitals  | |  lx,lX      |  uint32_t      |unsigned hexadecimal, X uses capitals  |
|  lp,lP      |  uint32_t      |pointer, P uses capitals  | |  lp,lP      |  uint32_t      |pointer, P uses capitals  |
 +^  ^  ^  ^
 +|  lld,lli    |  int64_t        |signed decimal  |
 +|  llo        |  uint64_t      |unsigned octal  |
 +|  llu        |  uint64_t      |unsigned decimal  |
 +|  llx,llX    |  uint64_t      |unsigned hexadecimal, X uses capitals  |
^  ^  ^  ^ ^  ^  ^  ^
|  a,A        |  double/float  |double in hex format +-h.hhh**p**+-d  | |  a,A        |  double/float  |double in hex format +-h.hhh**p**+-d  |
Line 194: Line 209:
|  %          |  none          |output a %  | |  %          |  none          |output a %  |
-**NOTE:** Some or all of these converters may be disabled by the target's library config file.  By default "aefg" is disabled.  Float to text conversion can also be performed by [[dtoa]] and family.+**NOTE:** Some or all of these converters may be disabled by the target's library config file.  Float to text conversion can also be performed by [[dtoa]] and family.
If an error occurs, -(# chars output + 1) is returned with the carry flag set and //errno// set to: If an error occurs, -(# chars output + 1) is returned with the carry flag set and //errno// set to:
 
libnew/stdio.1438402206.txt.gz · Last modified: 2015/08/01 05:10 by aralbrec
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki