National Instruments 320682C Musical Toy Instrument User Manual


 
Chapter 2 Formatting and I/O Library
© National Instruments Corporation 2-41 LabWindows/CVI Standard Libraries
Scanning Functions—Format String
Consider the following scanning function:
n = Scan(source, formatstring, targetptr1, ..., targetptrn);
where
formatstring
contains the information to transform the
source
argument to the
targetptr
arguments.
Format strings for the scanning functions are of the following form.
"source_spec > target_specs_and_literals"
where
source_spec
is a format specifier that describes the nature of the source parameter and
target_specs_and_literals
is a sequence of format specifiers and literal characters that
indicate how to divide and reformat the source argument into the desired target.
Examples of format strings for the scanning functions are:
"
%s
>
%i" "%s
>
%20f[w10x]"
The character
>
is a visual reminder of the direction of the data transformation, and also
separates the single source format specifier from the (possibly multiple) target format specifiers
and literals. The source format specifier can be omitted, in which case a
%s
string format is
assumed. If the source format specifier is omitted, the
>
character can be omitted also, or
retained for clarity.
Notice that the source format specifier is located to the left of the
>
symbol, just as the source
parameter is located to the left of the format string. Likewise, the target format specifiers are
located to the right of the
>
symbol, just as the target parameters are located to the right of the
format string.
Format specifiers describe the inputs and outputs of data transformations. Each format specifier
is of the following form.
% [ rep ] formatcode [[ modifiers ]]
The character
%
introduces all format specifiers.
rep
indicates how many times the format
repeats with respect to the arguments.
formatcode
is a code character which indicates the
nature of the data items being formatted.
modifiers
is an optional bracket enclosed sequence
of codes which further describe the data format.
The following are examples of format specifiers.
%s[t59] %100i[z] %f
Note:
rep
is not allowed when
formatcode
is
s
or
l
(string).