National Instruments 320682C Musical Toy Instrument User Manual


 
Formatting and I/O Library Chapter 2
LabWindows/CVI Standard Libraries 2-32 © National Instruments Corporation
Convert the integer value 23 to its ASCII representation and place the contents in a string
variable:
char a[5];
int b,n;
b = 23;
n = Fmt (a, "%s<%i", b);
After the
Fmt
call,
a
contains the string
23
.
In this example,
a
is the target argument,
b
is the source argument, and the string
%s<%i
is the
format string. The
Fmt
call uses the format string to determine how to convert the source
argument into the target argument.
With the
Scan
function, you can convert the string
23
to an integer:
char *a;
a = "23";
n = Scan (a$, "%s>%i", b%);
After the
Scan
call,
b
= 23.
In this example,
a
is the source argument,
b
is the target argument, and
%s>%i
is the format
string. In both the formatting and the scanning functions, the format string defines the variable
types of the source and target arguments and the method by which the source arguments are
transformed into the target arguments.
Formatting Functions
The following information is a brief description of the three formatting functions:
n = Fmt (target, formatstring, source1, ..., sourcen);
The
Fmt
function formats the
source1, ..., sourcen
arguments according to
descriptions in the
formatstring
argument. The function places the result of the
formatting into the
target
argument.
n = FmtFile (handle, formatstring, source1, ..., sourcen);
The
FmtFile
function formats the
source1, ..., sourcen
arguments according to
descriptions in the
formatstring
argument. The function writes the result of the
formatting into the file corresponding to the
handle
argument.
n = FmtOut (formatstring, source1, ..., sourcen);
The
FmtOut
function formats the
source1, ..., sourcen
arguments according to
descriptions in the
formatstring
argument. The function writes the result of the
formatting to Standard Out.