Chapter 2 Formatting and I/O Library
© National Instruments Corporation 2-55 LabWindows/CVI Standard Libraries
Real Array to Binary File, Assuming a Variable Number of Elements
void StoreArray (double x[], int count, char filename[])
{int file_handle;
file_handle = OpenFile (filename, 2, 0, 0);
FmtFile (file_handle, "%*f<%*f", count, count, x);
CloseFile (file_handle);
}
Remarks
This example shows how a function can be used to write an array of real numbers to a binary file.
The function's parameters are a real array, the number of elements to be written, and the
filename.
The FmtFile call writes the first count elements of x to a file in binary form. The two
asterisks (*) in the format string are matched to count. For instance, if count is 100, then the
format string is equivalent to %100f<100f.
A Variable Portion of a Real Array to a Binary File
void StoreSubArray (double x[], int start, int count, char filename[])
{int file_handle;
file_handle = OpenFile (filename, 2, 0, 0);
FmtFile (file_handle, "%*f<%*f[i*]", count, count, start, x);
CloseFile (file_handle)
}
Remarks
This example is an extension of the previous example. The function also writes a variable
number of elements of a real array to a file. Instead of beginning at the first element of the array,
a starting index is passed to the function.
The FmtFile call writes count elements of x, starting from x[start], to a file in binary
form. The first two asterisks (*) in the format string are matched to count. The third asterisk
is matched to start. For instance, if count is 100 and start is 30, then the format string is
equivalent to %100f<100f[i30]. Because the i modifier specifies a zero-based index into
the real array, the array elements from x[30] through x[129] are written to the file.