替换文件内容 [英] Replace file content

查看:68
本文介绍了替换文件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个文件,
首先

I have 2 files,
first

t1- x,y,z
t2- a,b,c
.
.
so on


第二


second

x=1
y=2
z=3
a=4
.
. so on


我想替换第二个文件的内容
例子


I want to replace the content of file one wrt file second
example

t1- 1,2,3
t2- 4,5,6
.
.
so on.

推荐答案

我们不做作业:它的设置是有原因的.在这里,您可以考虑自己被告知的内容,并尝试理解它.也可以在那里帮助您的导师识别您的弱点,并将更多的注意力放在补救措施上.

自己尝试,您可能会发现它并不像您想的那么困难!
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!


您必须解析两个文件.
如果您的文件确实那么正常,那么您可以只使用有利可图的fscanffprintf来完成工作.
例如
You have to parse both the files.
If your files are really so regular then you may just use profitably fscanf and fprintf for the job.
For instance
if ( fscanf(fp "%c=%d", &name, &value) == 2)
{
  // here add the pair {name, value} to the look up table
}


是用于第二个文件条目的非常粗糙的行解析器.

如果您需要处理更复杂的情况(例如,多个空格,更长的标识符名称),则可以使用awkbison & flex之类的解析工具.


is a very rough line-parser for second file entries.

If you need to handle more complex scenarios (for instance multiple blanks, longer identifier names) then you may use awk or parsing tools tools like bison & flex.


这篇关于替换文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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