Formatting and I/O Library Chapter 2
LabWindows/CVI Standard Libraries 2-54 © National Instruments Corporation
if ((i % 5) == 4)
WriteFile (file_handle, "\n", 1);
}
CloseFile (file_handle);
Remarks
The FmtFile call writes the ASCII representation of a real array element to the file, followed
by a comma. The w modifier specifies that the number be right-justified in a 15-character field.
The WriteFile call writes a linefeed to the file after every fifth call to FmtFile. Because
the file is opened in ASCII mode, the linefeed is automatically written as a linefeed/carriage
return combination.
Note: If the format string is "%s[w15]<%f,", the number and the comma are left-justified
together in a 15-character field.
Integer Array to Binary File, Assuming a Fixed Number of Elements
int readings[100];
int file_handle, nbytes;
file_handle = OpenFile ("FILE.DAT", 2, 0, 0);
FmtFile (file_handle, "%100i<%100i", readings);
nbytes = NumFmtdBytes ();
CloseFile (file_handle)
Remarks
The FmtFile call writes all 100 elements of the integer array readings to a file in binary
form. If the FmtFile call is successful, nbytes = 200 (100 integers, 2 bytes per integer).
Real Array to Binary File, Assuming a Fixed Number of Elements
double waveform[100];
int file_handle, nbytes;
file_handle = OpenFile ("FILE.DAT", 2, 0, 0);
FmtFile (file_handle, "%100f<%100f", waveform);
nbytes = NumFmtdBytes ();
CloseFile (file_handle);
Remarks
The FmtFile call writes all 100 elements of the real array waveform to a file in binary form.
If the FmtFile call is successful, nbytes = 800 (100 integers, 8 bytes per real number).