I have a program written in C, that was written by a co-worker. I want to add a line of code that will output certain structures that are within a If loop inside the program, to a text file. How do i do that?
Adding a line that will output some information to a text file in a C program
Collapse
X
-
Before the loop call fopen to open or create your file.
Inside the loop call fwrite to write data to your file.
After the loop call fclose() close the file.
There are plenty of tutorials on the Internet on how to use these functions. -
So i want to write these structures to a file inside the following loop
Code:if(fread(&data1,sizeof(struct applanix_data_group1),1,fp)==1) { sbet.gpstime = time_sod; sbet.latitude = data1.latitude * DEGREES2RADIANS; sbet.longitude = data1.longitude * DEGREES2RADIANS; sbet.altitude = data1.altitude; (there are other structures in this loops but these are the ones that i need) }
Comment
-
You would probably use an fwrite function call for each data item followed by one fwrite call to write a \n.
I really recommend you write a small program to open a file, write data to it, close the file so you can verify you know how to do this. Then apply that knowledge to this program.Comment
Comment