如何使用c替换一个文件中的特定数据与另一个文件中的数据? [英] How to replace specific data in one file with the data in another file using c?

查看:85
本文介绍了如何使用c替换一个文件中的特定数据与另一个文件中的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个文件中的特定数据替换为另一个文件中的数据使用c

以下是我的条形码标签...



i'm trying to replace specific data in one file with the data in another file using c
following is my barcode label...

c0001
f260
L
D11
H30
R0000
C0040
1X1100000100010B300300003003
181100202900027Part No
181100202900097[PRTNUM]
1e5504002400030B
1X1100002300010L300003
191100202000030Quantity
191100202000080[QUANTY]
1e5504001500040B
1X1100001400010L300003
1X1100001400150L003090
191100202000170P.O.No
191100202000220[PONUMB]
1e5504001500180B
191100201200030Supplier
1e3304000700030B
1X1100000600010L300003
181100200300030Serial
181100200300090[SERIAL]
171100300900190Rev
171100300300190[REV]
171100300900240Units
171100300300240[UNITS]
1X1100000100180L003130
Q0001
E

< br $> b $ b



&另一个文件中的内容如下:






& the content in another file is as below

132424235
004342
L1000
DZ12
234235
234235







i希望用数据004342替换第一个文件中的字段[PRTNUM]在这种方式的另一个文件中我希望[]内的所有数据都被其他文件中的数据替换。




i want to replace field [PRTNUM] from first file with data 004342 in another file in this way i want all data inside [] is replaced by data from other file.

推荐答案

你不一定只是替换数据 file:如果数据的长度与替换的长度相同,则可以打开文件,查找位置,写入新数据,保存文件并关闭它。



但是......如果不是那么你必须将输入文件复制到新的输出文件中直到第一次替换,将新的infor写入输出文件,跳过旧的旧信息文件,将输入文件的其余部分复制到输出,保存输出并关闭它们,然后删除旧文件,并重命名新文件。
You can't necessarily just "replace data" in a file: if the data is the same length as it's replacement, you can open the file, seek to the position, write the new data, save the file, and close it.

But...if it isn't then you have to copy the input file into a new output file up to the point of the first replacement, write the new infor to the output file, skip the old information in the old file, copy the rest of the input file to the output, save the output and close them both, then delete the old file, and rename the new one.


这篇关于如何使用c替换一个文件中的特定数据与另一个文件中的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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