473,326 Members | 2,061 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,326 software developers and data experts.

adding colums to text

I have a row of values like such, placed in a text file by fprintf.

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.

Bill
Jun 28 '08
60 2609
"Bill Cunningham" <no****@nspam.comwrites:
"Keith Thompson" <ks***@mib.orgwrote in message
news:lz************@stalkings.ghoti.net...
You're asking questions that are so elementary that you're practically
asking us to write the program for you.

Hmm.

Ok, here's an outline in English:

Keep track of the number of lines you've read and of the sum of the
numbers so far. Both start as 0 or 0.0.
For each line in the input file:
Get a floating-point number from the line.
Update the line counter and the sum.
Print the following on the output file:
The number you just read,
The sum of the numbers you've read so far,
The average of the numbers you've read so far
(the sum divided by the count).

You're talking about reading. I need to write the data first. I've
considered writing two functions to do this, one to write and one to read. I
need to start writing the data first. I have a program that writes the
single numbers and that's all.
So you already have a program that writes the data. If you're having
a problem with that, feel free to ask about it, but you haven't given
a hint about that so far.

Once you've written the data (which I've been assuming you've already
done), you need to read it, adding the extra information you've been
talking about. I've given you an outline of how to do that.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 1 '08 #51

"Keith Thompson" <ks***@mib.orgwrote in message
news:lz************@stalkings.ghoti.net...
So you already have a program that writes the data. If you're having
a problem with that, feel free to ask about it, but you haven't given
a hint about that so far.
That's what this post has been all about. Appending data as stated
earlier in the thread to already written data. My program work like this, I
enter p 12.00 and continue with different numbers and a list is printed.

12.00
5.00
12.30

I enter "p" for print and each number and a text file is written. Reading it
mean I'm going to have to learn new functions and I'm happy to do it. If I
can identify them. I've been warned about fscanf and told to use it both.

Bill
Jul 1 '08 #52
"Bill Cunningham" <no****@nspam.comwrites:
"Keith Thompson" <ks***@mib.orgwrote in message
news:lz************@stalkings.ghoti.net...
So you already have a program that writes the data. If you're having
a problem with that, feel free to ask about it, but you haven't given
a hint about that so far.

That's what this post has been all about. Appending data as stated
earlier in the thread to already written data. My program work like this, I
enter p 12.00 and continue with different numbers and a list is printed.

12.00
5.00
12.30

I enter "p" for print and each number and a text file is written. Reading it
mean I'm going to have to learn new functions and I'm happy to do it. If I
can identify them. I've been warned about fscanf and told to use it both.
I'm afraid you've lost me.

Upthread, I gave you an outline for how to read your existing
data and write the final result you're looking for, assuming that
you already have the single-column input file. You hadn't said
anything about needing to generate the single-column input file.
In response, you wrote:

| You're talking about reading. I need to write the data first. I've
| considered writing two functions to do this, one to write and one to read. I
| need to start writing the data first. I have a program that writes the
| single numbers and that's all.

Do you already have the single-column input file or not?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 1 '08 #53

"Keith Thompson" <ks***@mib.orgwrote in message
news:lz************@stalkings.ghoti.net...
Do you already have the single-column input file or not?
Yes the text file is for the ouput I type in. I type p 12.00 a file that
doesn't exist is created called "data". I type p 12.11 and it is added below
as such.

12.00
12.11

What I was asking in this thread was to append after 12.11 say

24.11

But your are telling me that can be calculated and that's much simpler.

Bill
Jul 2 '08 #54
On Tue, 01 Jul 2008 01:01:51 GMT, "Bill Cunningham" <no****@nspam.com>
wrote:
>
"Barry Schwarz" <sc******@dqel.comwrote in message
news:8q********************************@4ax.com.. .
>Initialize an int to zero. After reading each line, add one to the
int (or, if you are feeling brave, increment the int).

Could you give me an example of this? Would you use for ?

int count=0;
What would be the trigger to increment?
You troll much better when you don't post so often. You deliberately
left out your question that my post responded to. And you obviously
chose to ignore what I wrote. What part of "After reading" doesn't
sound like a trigger to you?
Remove del for email
Jul 2 '08 #55
On Tue, 01 Jul 2008 17:28:18 GMT, "Bill Cunningham" <no****@nspam.com>
wrote:
>
"Keith Thompson" <ks***@mib.orgwrote in message
news:lz************@stalkings.ghoti.net...
>You're asking questions that are so elementary that you're practically
asking us to write the program for you.

Hmm.

Ok, here's an outline in English:

Keep track of the number of lines you've read and of the sum of the
numbers so far. Both start as 0 or 0.0.
For each line in the input file:
Get a floating-point number from the line.
Update the line counter and the sum.
Print the following on the output file:
The number you just read,
The sum of the numbers you've read so far,
The average of the numbers you've read so far
(the sum divided by the count).

You're talking about reading. I need to write the data first. I've
considered writing two functions to do this, one to write and one to read. I
need to start writing the data first. I have a program that writes the
single numbers and that's all.
I quote from your first post -

I have a row of values like such, placed in a text file by
fprintf.

I take it you are just lying to us for sport.
Remove del for email
Jul 2 '08 #56
Barry Schwarz <sc******@dqel.comwrites:
On Tue, 01 Jul 2008 17:28:18 GMT, "Bill Cunningham" <no****@nspam.com>
wrote:
"Keith Thompson" <ks***@mib.orgwrote in message
news:lz************@stalkings.ghoti.net...
You're asking questions that are so elementary that you're practically
asking us to write the program for you.

Hmm.

Ok, here's an outline in English:

Keep track of the number of lines you've read and of the sum of the
numbers so far. Both start as 0 or 0.0.
For each line in the input file:
Get a floating-point number from the line.
Update the line counter and the sum.
Print the following on the output file:
The number you just read,
The sum of the numbers you've read so far,
The average of the numbers you've read so far
(the sum divided by the count).
You're talking about reading. I need to write the data
first. I've considered writing two functions to do this, one to
write and one to read. I need to start writing the data first. I
have a program that writes the single numbers and that's all.

I quote from your first post -

I have a row of values like such, placed in a text file by
fprintf.

I take it you are just lying to us for sport.
I'm having difficulty not reaching the same conclusion.

Bill, assuming you're not deliberately trolling, consider this. If
you had originally written something like this:

I have a text file with one floating-point number on each line.
I want to append the cumulative sum and the mean to each line.

For example, given this input:

10.50
10.25
10.00
10.75
11.00

I want to produce this output:

10.50 10.50 10.50
10.25 20.75 10.38
10.00 30.75 10.25
10.75 41.50 10.38
11.00 52.50 10.50

Now I can understand failing to ask a question clearly on the first
try. There's a great deal of skill in asking good questions.

But after multiple attempts to get you to state what you're trying to
do, you have repeatedly failed to significantly clarify anything. You
have evaded or ignored simple direct questions. I'm *still* not
certain that the above is an accurate description.

If you post a question, and somebody asks you a specific question
about your problem, then *answer the question*. If you're unwilling
to help us to understand what you're asking, we can't possibly help
you.

(And if you *are* deliberately trolling, then you're wasting a great
deal of the time of people who are simply trying to help someone
learn. If you find that kind of thing amusing, then I pity you.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 2 '08 #57
Keith Thompson <ks***@mib.orgwrites:
[...]
Bill, assuming you're not deliberately trolling, consider this. If
you had originally written something like this:

I have a text file with one floating-point number on each line.
I want to append the cumulative sum and the mean to each line.

For example, given this input:

10.50
10.25
10.00
10.75
11.00

I want to produce this output:

10.50 10.50 10.50
10.25 20.75 10.38
10.00 30.75 10.25
10.75 41.50 10.38
11.00 52.50 10.50
.... then we could have avoided wasting a good deal of time. (I
inadvertently failed to complete the sentence in the previous post.)

[...]

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 2 '08 #58
Keith Thompson said:

<snip>
If you post a question, and somebody asks you a specific question
about your problem, then *answer the question*. If you're unwilling
to help us to understand what you're asking, we can't possibly help
you.

(And if you *are* deliberately trolling, then you're wasting a great
deal of the time of people who are simply trying to help someone
learn. If you find that kind of thing amusing, then I pity you.)
"How long, how long must we sing this song?" - U2

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google Groups users, please read: <http://improve-usenet.org/>
"Usenet is a strange place" - dmr 29 July 1999
Jul 2 '08 #59
Keith Thompson wrote:
(And if you are deliberately trolling, then you're wasting a great
deal of the time of people who are simply trying to help someone
learn. If you find that kind of thing amusing, then I pity you.)
Same old songs and all that, but I don't know that it matters. Whether
it's a deliberate troll or not, I don't see any progress with Bill over
the years. I believe it is a waste of time regardless. If he's not a
troll, then through mental tics or stubborness Bill is not able to
participate in a meaningful fashion.

I went through this with him months ago. I said that he would need to
stick to one problem, work it through, answer all questions, yadda
yadda. He didn't. I plonked him. I don't even need to worry about him
being a troll.

Brian

Jul 2 '08 #60
On 29 Jun 2008 19:50:49 -0700, Keith Thompson <ks***@mib.orgwrote:
"Bill Cunningham" <no****@nspam.comwrites:
I am trying to create a moving average of data. Whether it be for 5-10-30
days of securitites prices.

I'm not sure, but I *think* you've finally answered the question I
asked at least twice, if only indirectly.

Each input line contains a number. Each output line contains the
number from the corresponding input line, followed by the sum of all
the input numbers seen so far, followed by the mean of all the input
numbers so far.
Actually that _isn't_ a moving average, but rather a running average.
It is a different, although also sometimes useful, statistic, and
might be just as good to move Bill C a step or two further along --
inasmuch as he seems to have difficulty, that appears to me to be
roughly constant, with any algorithm beyond "hello world".

I note this just in (unlikely) case someone else who does indeed
want/need moving average should happen on this thread.

- formerly david.thompson1 || achar(64) || worldnet.att.net
Jul 14 '08 #61

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ajay Garg | last post by:
What is the way we could implement a business logic from a Table by storing it statemnnets in a colums and defining an execute sql to execute it.Some legal requirements make it diffcult for us to...
5
by: Joy | last post by:
Hi guys, I am in a tricky situation, I really really hope someone will help me. I got a layout with a main container and three colums inside. Main container: 100% height; 90% width; float: left...
0
by: Bernard Dhooghe | last post by:
In http://www-1.ibm.com/partnerworld/pwhome.nsf/weblook/eac_a_webcast_052504.html the writer says (page 50, Multidimensional Clustering Advisor): " The MDC Advisor feature of the DB2 Design...
1
by: Patrick Olurotimi Ige | last post by:
I want to add a HeaderText="Subject" and HeaderImageUrl="" to a Datagrid but it seems it doesn't work! It seems If i specify both header text and a header image, the header image takes...
1
by: basulasz | last post by:
May be it is a bit easy question but i don't know the way to display data in bounded colums. I get data from DB with a datareader, and I want to display them on bounded colums. I dont want to...
1
by: Shilpa | last post by:
Hi , I am shilpa. I have one grid. I am adding data to teh grid thorugh xml. Now i have to create a hyperlink colums when i add data to the grid depending on the value selected in another drop...
1
by: bonk | last post by:
I have a very simple UserControl (derived from System.Windows.Forms.UserControl) that contains several ListViews. The UserControl exposes a single public property: public...
0
by: zafar | last post by:
I don't know what property should be used for hiding colums in Data Grid, whereas in Data Grid View we have DataGridView1.Colums(index).Visible = False , But how can I hide Colums in Data Grid.....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.