473,387 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Adding a line that will output some information to a text file in a C program

2
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?
Aug 20 '13 #1
3 1321
weaknessforcats
9,208 Expert Mod 8TB
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.
Aug 20 '13 #2
CBnasa
2
@weaknessforcats






So i want to write these structures to a file inside the following loop

Expand|Select|Wrap|Line Numbers
  1.  if(fread(&data1,sizeof(struct applanix_data_group1),1,fp)==1)
  2.      {
  3.  
  4.         sbet.gpstime = time_sod;
  5.         sbet.latitude = data1.latitude * DEGREES2RADIANS;
  6.         sbet.longitude = data1.longitude * DEGREES2RADIANS;
  7.         sbet.altitude = data1.altitude;
  8.  
  9. (there are other structures in this loops but these are the ones that i need)
  10.      }
So how would i write the fwrite command to only output these structures to a text file?
Aug 20 '13 #3
weaknessforcats
9,208 Expert Mod 8TB
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.
Aug 20 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: qbschmidt | last post by:
i can input and output to a text file as long as the file is in the same directory as my c++ program. but i cant figure out how to input/output to a file in another directory i.e. I:\c++projects...
2
by: Joe Saliba | last post by:
hi, we're trying to output a text file in other format including delimeters (; instead of , ) and changing text delimeters too any way to do it from vb ?? thx *** Sent via Developersdex...
3
by: Jeff | last post by:
This is not as simple as I thought. Using Print # I am outputting content for a text file. I wanted at certain points to force a page break so I thought a Chr(12) for a form feed may work. If...
0
by: Trent USTA | last post by:
I'm having a problem with line feeds in an xslcompiledtransform in .net 2.0. I'm trying to use xsl to transform xml to a text file that can be read on a Unix box. The problem is that when I insert...
5
by: ComicCaper | last post by:
Hi all, I use a quiz program that accepts a text file for questions and answers in this format: Question Answer1 <----is the correct answer. Quiz randomizes answers. Answer2 Answer3...
1
by: galivio | last post by:
I need a code in C where accepts inputs coming from an external text file and will give an output stored on another text file. For example, a C program to compute the sum of the two integers. The...
1
by: rafnavsun | last post by:
Hi Everybody, I need to concatenate all records on one field as one line. Example: Field 1 has 50 records, record1, record2 to record50. I need to display an output in Text that read as: ...
13
by: jhamb | last post by:
Hi, This code is in Perl (just a trial, not tested) to parse a text file and output to another file. It is used to delete lines that are not required and output lines that the user wants, to a new...
3
by: xyz | last post by:
Hi, I have a text file around 7GB includes 100 million lines... I want to read the data line by line when I approach my module.. ie., when i read for the first time , my program shuld read only...
0
by: grant | last post by:
I have a transfer data task that gets some data from a table and outputs it to a pipe delimitd text file. How can I configure a transfer data task so it outputs the field names from the table in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.