| Using VISA.NET > Formatted I/O > Using Scanf > Scanf Format Specifier Syntax > Scanf Modifiers |
The supported modifiers in the Scanf format specifier are:
The width modifier is optional. You can use a width modifier with characters and strings (types c , s, [<m>], [^<m>], t, and T), integers (types d, i, o, u, x, and X), and real numbers (types e, E, f, g, and G). Width is not valid for IEEE 488.2 blocks (types b and B) or raw binary arrays (type y).
Width specifies the maximum number of characters to be parsed for this specifier. Fewer than width characters may be read if a whitespace character (space, tab, or newline) or a character that cannot be converted according to the given format occurs before width is reached.
If an array is specified, width applies to each element individually.
If width is '#', then the value of width is read from the Scanf inputs array argument. The argument precedes the arraySize input argument, if it is specified. The width input argument may be a signed or unsigned positive integer.
![]() |
Do not use width values that are not signed or unsigned positive integers (such as zero, fractions, and negative numbers). For such values, the results are undefined, and Scanf may throw an exception. Since Scanf does not always throw an exception when width is invalid, it is important that width always be a signed or unsigned positive integer. |
The array modifier is the ',' (comma) character followed by an optional arraySize argument. It indicates an array of numbers, optionally followed by arraySize – the number of elements to be formatted. It is only necessary to include arraySize if the number of elements to be read is less than the number of elements in the output array argument.
The array size modifier is optional. You can use it with integers (types d, i, o, u, x, and X), real numbers (types e, E, f, g, and G), IEEE 488.2 blocks (type b), or raw binary arrays (type y). Array size is not valid for characters (type c) and strings (type s).
For integer and real types, arrays indicated by the ',' modifier are formatted as comma-separated lists, with each element formatted according to the format specifier.
The array size is determined as follows:
![]() |
Do not use arraySize values less than or equal to 0, greater than the size of the associated array, or fractional. For such values, the results are undefined, and Scanf may throw an exception. Note that since Scanf does not always throw an exception when the arraySize is invalid, it is important that arraySize always be a signed or unsigned positive integer. |
Size modifiers indicate the size of the data to be formatted.
|
Modifier |
Applicable Types |
Description |
|---|---|---|
|
b (default) |
b, y |
Array elements are interpreted as 8-bit integers. |
|
h |
b, y |
Array elements are interpreted as 16-bit integers. |
|
l (lowercase L) |
b, y |
Array elements are interpreted as 32-bit integers. |
|
ll (lowercase LL) |
y |
Array elements are interpreted as 64-bit integers. |
|
z |
b |
Array elements are interpreted as 32-bit reals. |
|
Z |
b |
Array elements are interpreted as 64-bit reals. |
![]() |
Do not use size modifiers not listed in the above table, and do not use a size modifier with format types that are not applicable (as shown in the table above). In such cases, the results are undefined, and Scanf may throw an exception. Since Scanf does not always throw an exception when the size modifier is invalid, it is important that size modifiers always be used with applicable types as indicated in the above table. |