471,092 Members | 1,429 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

How to load and output a text file in C?

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 value of the two integers are taken in a text file, example "input.txt" and written in this manner:

2 3

where 2 is the value of the first integer and 3 is the value of the second integer. The code should load the text file and assign variables to the values. I need to output the result in a separate text file example "output.txt" and should contain the sum of the two integers which in this example it's:


I guess it should be stored in an array. I just don't know what function to use to load and outpu a text file. Actually, our project is like this, the input text conatins the following info:

<p i>
<p 0> <p 0 int1> <p 0 int2>
<p 1> <p 1 int1> <p 1 int2>
<p n-1> <p n-1 int1> <p n-1 int2>

where <p i> is the total number of processes, <p 0> is the process 1, <p 0 int1> is the value of the first integer of <p 0> process, <p 0 int2> is the value of the first integer of <p 0> process... and so on...

example (input.txt):

1 3 2
2 3 4
3 4 5

the output should be in a textfile (output.txt) and would look like this:

<p i>
<p 0> <p 0 sum2>
<p 1> <p 1 sum1>
<p n-1> <p n-1 sumn-1>

example (output.txt):

1 5
2 7
3 9

Please, give me the code.... Need it badly.
Sep 23 '06 #1
1 4587
9,065 Expert Mod 8TB
Look you the functions



on line or in you handy C programming book.
Sep 23 '06 #2

Post your reply

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

Similar topics

reply views Thread by Montagna, Dan | last post: by
6 posts views Thread by acord | last post: by

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.