Chapter 2 Formatting and I/O Library
© National Instruments Corporation 2-53 LabWindows/CVI Standard Libraries
Integer and Real to String with Literals
char buf[20];
int f, r;
double v;
f = 4;
r = 3;
v = 1.2;
Fmt (buf, "%s<F%iR%i; V%f;", f, r, v);
Remarks
After the Fmt call, buf contains "F4R3; V1.2;".
Two Integers to ASCII File with Error Checking
int a, b, n, file_handle;
a = 12;
b = 456;
file_handle = OpenFile ("FILE.DAT", 2, 0, 1);
if (file_handle < 0) {
FmtOut ("Error opening file\n");
exit (1);
}
n = FmtFile (file_handle, "%s<%i %i", a, b);
if (n != 2) {
FmtOut ("Error writing file\n");
exit (1);
}
CloseFile (file_handle);
Remarks
OpenFile opens the file FILE.DAT as an ASCII file for writing only. If the function
succeeds, it returns a file handle with a positive integer value. FmtFile writes the ASCII
representation of two integer values to the file. If FmtFile succeeds, it returns 2 (because there
are two source specifiers in the format string).
Real Array to ASCII File in Columns and with Comma Separators
double x[100];
int file_handle, i;
file_handle = OpenFile ("FILE.DAT", 2, 0, 1);
for (i=0; i < 100; i++) {
FmtFile (file_handle, "%s<%f[w15],", x[i]);