473,387 Members | 1,942 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.

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:

3

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):

3
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):

3
1 5
2 7
3 9

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

fopen
fclose

fread
fwrite
fgets
fprintf
fgetchar
fputchar

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

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

Similar topics

4
by: MJL | last post by:
Suppose you have a perl program that is called by a web page to generate another web page. The program is written to load data from a text file on the server and make certain substitutions in the...
6
by: matt | last post by:
I am using a text file as a database, each field delimited by || I want to be able to print all lines to a page, then by selecting one (with, say, a radio button) it will load into the form at the...
0
by: Montagna, Dan | last post by:
------_=_NextPart_001_01C35B55.62B4A6E0 Content-Type: text/plain; charset="iso-8859-1" Hello, I'm a very new mysql/php user and am trying to use the load data infile command without luck. I'd...
2
by: Sam | last post by:
I have a custom control (MyTextBox - taken from Microsoft website) that implements the IPostBackDataHandler interface. It is added to the controls collection of a placeholder control during the...
5
by: Engineerik | last post by:
I have a login form which I want to display with the showdialog method. When I do that the event handler for the load event does not run. If I use the show method the load event handler runs...
6
by: acord | last post by:
Hi, In a html page, I don't know how to load in a php page from javascript. I've already defined a <div id="treemenu"> in the html page. The executed content from the php script is supposed...
2
by: whisher | last post by:
Hi. I'm taking my first steps with xml and SimpleXML functions. xml.php (It could be made dynamically with a mysql result I post this snippet for example ) PHP Code xml.php: <?php $xmlstr...
0
by: mrjaxon | last post by:
Basically the issue is, when the XSL style sheet is loaded by URI it is cool but when the exact same style sheet loaded by it's contents the load fails (for this particular style sheet). Because...
2
by: wsdcent | last post by:
Hi every one. I'm trying to read a xml file dynamically from mysql database . There is my actual code: It only works if the file is a local file or if is an absolute path. Whenever i try to load...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.