From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to write int. and char data in to a text file in CVI?

I am having trouble writing data to text file in CVI. All I want is to be able to enter data from Panel and write to a text file. I am just not sure my parameter should be. Any help?
0 Kudos
Message 1 of 5
(3,798 Views)
Hi,

Have you looked at the WriteFile function? Here's the documentation for that function:

This function writes the specified number of bytes to a file from a string buffer.

CAUTION: The Windows SDK also contains a WriteFile function. If you include windows.h and do not include formatio.h, you will get compile errors if you call the WriteFile function.


/*-------------------- Prototype ---------------------*/
int WriteFile (int File_Handle, char Buffer[], int Count);


Or, if you are writing an array to a file, I would suggest the ArrayToFile function. There is a good example program in CVI under Fundamentals >> File Input and Output >> arrayfile.prj that demonstrates this function.

Note that if you right-click on any function panel, the Funct
ion Help is automatically displayed for that function. The same is true if you right-click on a particular control input.

Good luck!

Kileen C.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 5
(3,798 Views)
You can also use the ANSI C fprintf() function if you want to create your own formatting and delimiters. For example:
#include
int myInt;
char myString[256];
FILE *myFile;
/* you'll call GetCtrlVal() instead of the next two assignment statements */
myInt = 256;
strcpy (myString, "Hello world!");
myFile = fopen ("eraseme.txt", "w");
fprintf (myFile, "%d\t%s\n", myInt, myString);
fclose (myFile);
0 Kudos
Message 3 of 5
(3,798 Views)
Hi,

You may also want to look at the example installed at C:\Program Files\National Instruments\CVI70\samples\fileio . It's a good example for ASCI and binary data.

Just my 2 cents.

Juan Carlos
N.I.
0 Kudos
Message 4 of 5
(3,798 Views)
Thanks a bunch for your input. I did get an idea for I wanted to do from this example.

Thanks again!
0 Kudos
Message 5 of 5
(3,798 Views)