将colums添加到文本中 [英] adding colums to text

查看:94
本文介绍了将colums添加到文本中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一排像这样的值,由fprintf放在一个文本文件中。


10.50

10.25

10.00

10.75

11.00


我想对上面的列做什么就是在它旁边添加一个新列

这是这些值的总和,然后在另一列中取平均值。

例如。


11.00 52.50


在另一栏中是5的平均值。


11.00 52.50 10.50


我假设fprintf将要使用,也许是开放的。


比尔

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

推荐答案

Bill Cunningham写道:
Bill Cunningham wrote:

我有一排这样的值,放在一个文本文件中由

fprintf。


10.50

10.25

10.00

10.75

11.00


我想对上面的列进行的操作是添加一个新列正确
旁边


这是这些值的总和,然后将它们平均在另一个

列中。例如。


11.00 52.50


在另一栏中是5的平均值。


11.00 52.50 10.50


我假设必须使用fprintf,也许

freopen。
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.



Fprintf就足够了。打印第一列的第一个条目,打印一个

选项卡,然后打印总计,另一个选项卡,然后是平均值,然后是

换行符,您的下一个值为第一列,换行符,下一个值

为第一列,换行符等等,直到所有值都打印出来为
。不要忘记在文件中添加最终换行符和

记得关闭它。

Fprintf is enough. Print the first entry of the first column, print a
tab, then print the total, another tab, then the average, then a
newline, your next value for the first column, a newline, next value
for the first column, a newline and so on, until all your values are
printed out. Don''t forget to add a final newline to the file and
remember to close it.


" Bill Cunningham" ; < no **** @ nspam.comwrites:
"Bill Cunningham" <no****@nspam.comwrites:

我有一行像这样的值,由fprintf放在文本文件中。


10.50

10.25

10.00

10.75

11.00


我想对上面的列进行的操作是在它旁边添加一个新列

这是这些值的总和,然后在另一列中取平均值。

例如。


11.00 52.50


在另一栏中是平均值5.

11.00 52.50 10.50


我假设必须使用fprintf并且可能是freopen。
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.



不,freopen不会有用。


您通常无法将数据插入现有文件。你可以用b $ b做什么来读取现有文件并写一个新文件(如果你愿意的话,

重命名新文件,以便它取代原来的文件)。 br />

作为第一步,尝试只读取现有文件并将

修改后的版本写入新文件。


-

Keith Thompson(The_Other_Keith) ks***@mib.org < http: //www.ghoti.net/~kst>

诺基亚

我们必须做点什么。这是事情。因此,我们必须这样做。

- Antony Jay和Jonathan Lynn,是部长

No, freopen isn''t going to be useful.

You generally can''t insert data into an existing file. What you can
do is read an existing file and write a new one (and, if you like,
rename the new file so it replaces the original one).

As a first step, try just reading the existing file and writing the
modified version to a new file.

--
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"




Keith Thompson < ks *** @ mib.org写信息

新闻:lz ************ @ stalkings.ghoti.net ...

"Keith Thompson" <ks***@mib.orgwrote in message
news:lz************@stalkings.ghoti.net...

不,freopen不会有用。


您通常无法将数据插入现有文件中。你可以用b $ b做什么来读取现有文件并写一个新文件(如果你愿意的话,

重命名新文件,以便它取代原来的文件)。 br />

作为第一步,尝试只读取现有文件并将

修改后的版本写入新文件。
No, freopen isn''t going to be useful.

You generally can''t insert data into an existing file. What you can
do is read an existing file and write a new one (and, if you like,
rename the new file so it replaces the original one).

As a first step, try just reading the existing file and writing the
modified version to a new file.



我知道你的意思但不是a fopen中的模式可以附加到现金数据吗?我会首先尝试Santosh的想法,并牢记你的建议。


比尔

I know what you mean but isn''t the "a" mode in fopen for appending to
existing data? I will try Santosh''s idea first and keep your advice in mind.

Bill


这篇关于将colums添加到文本中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆