【发布时间】:2010-03-05 19:06:33
【问题描述】:
创建要写入的文件时是否需要 malloc?
该文件将基于其他 2 个文件的内容,所以我需要为 sizeof( file a ) + sizeof( file b) + 1 的可写文件分配空间吗?
对不起,如果这没有意义;如果不是,那么我想我需要多读一些:D
基本上,我有 2 个 txt 文件和一个字符串序列 - 我将每个文件的每一行并排写入,由字符串序列分隔。
txt file a
hello stack over
flow this
is a test
txt file b
jump the
gun i am
a novice
seperator == xx
output ==
hello stack overxxjump the
flow thisxxgun i am
is a testxxa novice
【问题讨论】:
-
文本文件还是二进制文件?您要合并 2 个文件吗?
-
你必须更好地说明你的目的。处理文件不一定涉及使用“malloc”,因此它取决于您的实际用例/目的。
-
基本上,我有 2 个 txt 文件和一个字符串序列 - 我正在并排写入每个文件的每一行,并由字符串序列分隔
-
我会温和地建议你在K&R中看一些这样的材料,这样会清楚得多。 (提示:从头开始,一直到此为止)