Re: adding colums to text
- From: pete <pfiland@xxxxxxxxxxxxxx>
- Date: Sun, 29 Jun 2008 07:57:42 -0400
pete wrote:
Barry Schwarz wrote:On Sat, 28 Jun 2008 23:11:13 -0400, pete <pfiland@xxxxxxxxxxxxxx>
wrote:
Bill Cunningham wrote:I have a row of values like such, placed in a text file by fprintf.Text files and linked lists, go together like hot dogs and mustard.
10.50
10.25
10.00
10.75
11.00
What I want to do to the above colum is add a new column right beside it which is a total of these values and then average them in another column. For example.
11.00 52.50
In another column is the average of the 5.
11.00 52.50 10.50
I am assuming that fprintf is going to have to be used and maybe freopen.
/* BEGIN new.c output */
File is open for writing.
File lines:
10.50
10.25
10.00
10.75
11.00
File is closed.
File is open for reading.
Reading file into a linked list...
File is closed.
snip code
Why on earth would you needlessly complicate such a simple task with
linked lists, especially given BC's previous posting history?
I posted that, because that's really how I would do it.
The first two things that popped into my head
were "linked list" and "extra temp file".
My preference is to always minimize the number of open files.
/* BEGIN new.c output */
File is open for writing.
File is closed.
File is open for reading.
File lines:
10.50
10.25
10.00
10.75
11.00
File is rewound.
Calculating sum and average.
sum is 52.500000. average is 5.250000
File is rewound.
Temp file is open for writing.
Reading file into a temp file...
File is closed.
Temp file is closed.
Temp file is open for reading.
File is open for writing.
File is closed.
Temp file is closed.
Temp file is removed.
File is open for reading.
File lines:
11.00 52.50 5.25
11.00 52.50 5.25
11.00 52.50 5.25
11.00 52.50 5.25
11.00 52.50 5.25
File is closed.
File is removed.
/* END new.c output */
I just noticed that the resulting file is wrong.
--
pete
.
- Follow-Ups:
- Re: adding colums to text
- From: pete
- Re: adding colums to text
- References:
- adding colums to text
- From: Bill Cunningham
- Re: adding colums to text
- From: pete
- Re: adding colums to text
- From: Barry Schwarz
- Re: adding colums to text
- From: pete
- adding colums to text
- Prev by Date: Re: adding colums to text
- Next by Date: Re: Storing input into a character array
- Previous by thread: Re: adding colums to text
- Next by thread: Re: adding colums to text
- Index(es):
Relevant Pages
|