468,503 Members | 2,214 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,503 developers. It's quick & easy.

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 4498
9,055 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
reply views Thread by NPC403 | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.