Chapter 2 Formatting and I/O Library
© National Instruments Corporation 2-67 LabWindows/CVI Standard Libraries
The first call to Scan treats the 1-byte integers as signed values (from -128 to +127). The
second call includes a u in the format string. This causes Scan to treat the 1-byte integers as
unsigned values (from 0 to 255).
String Containing Binary Integers to Integer Array
char s[200]; /* string containing 100 2-byte integers */
int ivals[100];/* 100 2-byte integers */
Scan (s, "%100i[z]>%100i", ivals);
Scan (s, "%97i[zi6]>%97i", ivals);
Remarks
Sometimes data from a programmable instrument is read into a character buffer even though it
contains binary data. This example shows how to treat a character buffer as an integer array.
The format string in each Scan call specifies that the source (s) contains an array of 100
integers. The z modifier is used to indicate that the source is actually a character buffer.
In some cases, the integer data may not start at the beginning of the character buffer. For
instance, the data in the buffer can begin with an ASCII header. In the second call to Scan, the
i6 modifier is used to indicate that the first 6 bytes of s are to be ignored.
Note: When the i modifier is used in conjunction with a character buffer, the number
following the i specifies the number of bytes within the buffer to ignore. This is true
even when the z modifier is also present. On the other hand, when the i modifier is
used in conjunction with an array variable, the number following the i indicates the
number of array elements to ignore.
String Containing an IEEE-Format Real Number to a Real Variable
char s[100];
double x;
Scan (s, "%1f[z]>%f", &x);
Scan (s, "%1f[zi5]>%f", &x);
Remarks
This example is similar to the previous example, except that s contains a single binary real
number (in IEEE format), rather an array of binary integers. The format string in each Scan call
indicates that the source (s) is to be treated as a 1-element array of real numbers. The z modifier
indicates that the source is actually a character buffer. The repetition count of 1 in the format
string is required; otherwise, the z modifier is not accepted.