National Instruments 320682C Musical Toy Instrument User Manual


 
Chapter 2 Formatting and I/O Library
© National Instruments Corporation 2-57 LabWindows/CVI Standard Libraries
case 2:
Fmt (buf, "%s<TRIANGLE;");
break;
}
switch (signal_output) {
case 0:
Fmt (buf, "%s[a]<OUTPUT OFF;");
break;
case 1:
Fmt (buf, "%s[a]<OUTPUT ON;");
break;
}
nbytes = StringLength (buf);
Remarks
This example shows how to append characters to a string without writing over the existing
contents of the string. The first
switch
construct writes one of three strings into
buf
. The
second
switch
construct appends one of two strings to the string already in
buf
. After the
call,
buf
contains
"SQUARE;OUTPUT OFF;"
. Notice that the
a
modifier applies to the
target specifier.
StringLength
returns the number of bytes in the resulting string. In this case,
StringLength
is used instead of
NumFmtdBytes
, because
NumFmtdBytes
would return
only the number of bytes appended.
Creating an Array of File Names
char *fname_array[4];
int i;
fname_array[0] = " "; /* 13 spaces */
fname_array[1] = " "; /* 13 spaces */
fname_array[2] = " "; /* 13 spaces */
fname_array[3] = " "; /* 13 spaces */
for (i=0; i < 4; i++)
Fmt (fname_array[i], "%s<FILE%i[w4p0].DAT", i);
Remarks
To allocate the space for each filename in the array, a separate constant string must be assigned
to each array element. Then
Fmt
is used to format each file name. The resulting file names are
FILE0000.DAT
,
FILE0001.DAT
,
FILE0002.DAT
, and
FILE0003.DAT
.