Chapter 2 Formatting and I/O Library
© National Instruments Corporation 2-69 LabWindows/CVI Standard Libraries
then reads the correct number of elements into values. The x modifier causes the comma
separators to be discarded.
Binary File to Integer Array, Assuming a Fixed Number of Elements
int readings[100];
int file_handle, nbytes;
file_handle = OpenFile ("FILE.DAT", 1, 2, 0);
ScanFile (file_handle, "%100i>%100i", readings);
nbytes = NumFmtdBytes ();
CloseFile (file_handle);
Remarks
The ScanFile call reads 100 integers from a binary file and stores them in the integer array
readings. If the ScanFile call is successful, nbytes = 200 (100 integers, 2 bytes per
integer).
Binary File to Real Array, Assuming a Fixed Number of Elements
double waveform[100];
int file_handle, nbytes;
file_handle = OpenFile ("FILE.DAT", 1, 2, 0);
ScanFile (file_handle, "%100f>%100f", waveform);
nbytes = NumFmtdBytes ();
CloseFile (file_handle);
Remarks
The ScanFile call reads 100 real numbers from a binary file and stores them in the real array
waveform. If the ScanFile call is successful, nbytes = 800 (100 integers, 8 bytes per real
number).
Binary File to Real Array, Assuming a Variable Number of Elements
void StoreArray (double x[], int count, char filename[])
{int file_handle;
file_handle = OpenFile (filename, 1, 2, 0);
ScanFile (file_handle, "%*f>%*f", count, count, x);
CloseFile (file_handle);
}