如何修改数据文件? [英] How do I modify a data file?

查看:160
本文介绍了如何修改数据文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从文件中读取浮点数,然后在文件中将每个浮点数乘以/除以一个浮点数.按比例改变文件中的浮点数并将它们限制在两个数字之间.从本质上讲,我有一个要发送的程序(浮动库仑)中的一个数据文件,我想让另一个程序来读取该文件,但是该数据的上/下变化幅度大于读取程序可以解释的值.我想用C语言做到这一点.请帮助我,我什么都没有.

I want to read floats, from a file and multiply/divide each float by a float, in the file. Varying the floats in a file proportionately and limit them between two numbers. essentially I have a data file from a sending program ( a coulomb of floats) that I want reed by another program but the data varies in value up/down more then the reading program can interpret. I''d like to do this in C language. Please help I have nothing.

推荐答案

假设您的文件包含浮点数,而不是二进制格式:
Assumeing that you file contains the floats as text rather than a binary format:
1.201
137.889
...


您将必须打开文件进行读写访问,将其读入程序(使用fscanf进行计算),然后重置文件流并再次将其全部写回.这是因为浮点数不能很好地适合文件:1.201占用的字符空间少于137.889,因此您不能只将更改的位写回到文件中,否则将覆盖数据.

您需要在此处提供一些详细信息: http://www.go4expert.com/forums/showthread .php?t = 2977 [^ ]


You will have to open the file for read-write access, read it into you program (using fscanf) do you calculations, then reset the file stream and write it all back out again. This is because floats do not fit neatly into the file: 1.201 takes up less space in characters than 137.889, so you cannot just write the changed bits back into the file, or you will overwrite the data.

There is some of the detail you will need here: http://www.go4expert.com/forums/showthread.php?t=2977[^]


同时(如果有)您可以访问第一个程序的输入界面
您可以在两个已知极限点(线性情况)之间建立平移定律"
或通过多点集(其他情况).
然后您可以使用法律:)
While (if) you have access to the input interface of the first program
you can build the "translation law" between the two known limit points (linear case)
or through a multipoint set (other case).
Then you can use the law :)


这篇关于如何修改数据文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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