文件合并 [英] File Merge

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

问题描述

我正在编写一个需要智能合并的应用程序。 2

个文件。也就是说,相等数据具有优选源。我想要
写出来。我相信,我的工作有点可怕,但看起来非常麻烦(必须将输入变量设置为......)。有更好的方式吗? TIA


while((!feof(wf3))||(!feof(wf1)))

{

if (!feof(wf1))

{

strcpy(WDBRec,"");

if(fgets(WDBRec,sizeof( WDBRec),wf1)!= NULL)

nic ++;

}

if(!feof(wf3))

{

strcpy(DBERec,"");

if(fgets(DBERec,sizeof(DBERec),wf3)!= NULL)

bic ++;

}

dbeBib = atoi(copy(DBERec,1,5));

wdbBib = atoi(copy (WDBRec,1,5));

if(wdbBib == dbeBib)//记录匹配 - 推迟旧数据

{

if(dbeBib> 0)

{

writeToDBE(DBERec); buc ++;

}

}

if(wdbBib< dbeBib)//工作文件数据是新的 - 写吧

{

if(wdbBib> 0)

{

writeToDBE(WDBRec); nuc ++;

}

else

{

if(dbeBib> 0)

{

writeToDBE(DBERec); buc ++;

}

}

}

if(wdbBib> dbeBib)//流行的旧数据 - 把它写出来

{

if(dbeBib> 0)

{

writeToDBE(DBERec); buc ++;

}

}

} //而

I''m writing an application that requires an "intelligent merge" of 2
files. That is, equal data has a "preferred source" that I want to
write out. What I have works, I believe, but it seems horribly
cumbersome (having to set the input variables to ""...). Is there a
better way? TIA

while ((!feof(wf3)) || (!feof(wf1)))
{
if (!feof(wf1))
{
strcpy(WDBRec, "");
if (fgets(WDBRec, sizeof(WDBRec), wf1) != NULL)
nic++;
}
if (!feof(wf3))
{
strcpy(DBERec, "");
if (fgets(DBERec, sizeof(DBERec), wf3) != NULL)
bic++;
}
dbeBib = atoi(copy(DBERec, 1, 5));
wdbBib = atoi(copy(WDBRec, 1, 5));
if (wdbBib == dbeBib) // records match - defer to old data
{
if (dbeBib > 0)
{
writeToDBE(DBERec); buc++;
}
}
if (wdbBib < dbeBib) // work file data is new - write it
{
if (wdbBib > 0)
{
writeToDBE(WDBRec); nuc++;
}
else
{
if (dbeBib > 0)
{
writeToDBE(DBERec); buc++;
}
}
}
if (wdbBib > dbeBib)// prevailing old data - write it out
{
if (dbeBib > 0)
{
writeToDBE(DBERec); buc++;
}
}
} // while

推荐答案


我正在编写一个需要智能合并的应用程序。
2个文件。也就是说,相等数据具有优选源。我想写出来。我相信,我的工作非常繁琐,但似乎非常麻烦(必须将输入变量设置为......)。有更好的方法吗? TIA

while((!feof(wf3))||(!feof(wf1)))
{
if(!feof(wf1))
{
strcpy(WDBRec,"");
if(fgets(WDBRec,sizeof(WDBRec),wf1)!= NULL)
nic ++;
}


[snipped]


首先:你的缩进有一些改进空间。其次,你是
与单行if语法的语法不一致。但这是我的

实际回复:


假设你没有使用UNICODE,你可以简化


strcpy(WDBRec,"");


to


WDBRec [0] =''\ 0'';


代码看起来不那么麻烦。你可以重写它,这可能会使得它更加直接:


if(fgets(WDBRec,sizeof(WDBRec),wfl)! = NULL)

{

nic ++;

wdbBib = atoi(copy(WDBRec,1,5));

}

其他

{

wdbBib = 0;

}


您使用的代码中的某个地方:

if(wdbBib> 0)
{/ / writeDBoDBE(WDBRec); nuc ++;
}
I''m writing an application that requires an "intelligent merge" of
2 files. That is, equal data has a "preferred source" that I want to
write out. What I have works, I believe, but it seems horribly
cumbersome (having to set the input variables to ""...). Is there a
better way? TIA

while ((!feof(wf3)) || (!feof(wf1)))
{
if (!feof(wf1))
{
strcpy(WDBRec, "");
if (fgets(WDBRec, sizeof(WDBRec), wf1) != NULL)
nic++;
}
[snipped]

Firstly: your indentation has some room for improvement. Secondly, you are
inconsistent with your syntax of single-line if bodies. But here is my
actual reply:

Assuming you are not working with UNICODE, you can simplify

strcpy(WDBRec, "");

to

WDBRec[0] = ''\0'';

The code doesn''t look that cumbersome. You could rewrite it, which may make
it a little bit more straight foreward:

if (fgets(WDBRec, sizeof(WDBRec), wfl) != NULL)
{
nic++;
wdbBib = atoi(copy(WDBRec, 1, 5));
}
else
{
wdbBib = 0;
}

Somewhere further down in your code you use:
if (wdbBib > 0)
{
writeToDBE(WDBRec); nuc++;
}




这样可以解决不写出无效字符串的问题(因为WDBRec

仍会包含以前的字符串价值)。


我可能会留下一些松散的关系,但这应该可以帮助你。


祝你好运!
< br $> b $ b -

Martijn
http: //www.sereneconcepts.nl


Martijn写道:
Martijn wrote:

.... snip ... <首先:你的缩进有一些改进的余地。
其次,你不符合你的单行语法
if body。但这是我的实际答复:
.... snip ...
Firstly: your indentation has some room for improvement.
Secondly, you are inconsistent with your syntax of single-line
if bodies. But here is my actual reply:




他的缩进在这里很好。这表明缩进

吞咽发生在通往你的路上的某个地方,但不是为了我b
。它可能是你的新闻阅读器,它似乎是一个微软

execresence。


你忽略了归因于你所引用的部分。请不要这样做。


-

查克F(cb ******** @ yahoo.com)(cb********@worldnet.att.net)

可用于咨询/临时嵌入式和系统。

< http ://cbfalconer.home.att.net>使用worldnet地址!



His indentation was fine here. This indicates that indentation
swallowing is taking place somewhere on the path to you, but not to
me. It could be your newsreader, which appears to be a Microsoft
execresence.

You neglected to attribute the portion you quoted. Please don''t do
that.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!


星期五,2005年8月5日07:59:58 GMT,CBFalconer

< cb ****** **@yahoo.com>写道:
On Fri, 05 Aug 2005 07:59:58 GMT, CBFalconer
<cb********@yahoo.com> wrote:
Martijn写道:
Martijn wrote:


... snip ...


... snip ...

其次,你的单行语法不符合
。但这是我的实际答复:

Firstly: your indentation has some room for improvement.
Secondly, you are inconsistent with your syntax of single-line
if bodies. But here is my actual reply:



他的缩进在这里很好。这表明缩进吞咽发生在通往你的路上的某个地方,但不是为了我。它可能是你的新闻阅读器,它似乎是一个微软
execresence。



His indentation was fine here. This indicates that indentation
swallowing is taking place somewhere on the path to you, but not to
me. It could be your newsreader, which appears to be a Microsoft
execresence.




原始使用的标签。令人讨厌的东西,他们可以扩展到任意数量的

空间,包括没有取决于系统(对我来说,他们扩展到8

空间,这是过度的,但只是可以忍受的例子)。


Chris C



The original used tabs. Nasty things, they can expand to any number of
spaces including none depending on the system (for me they expanded to 8
spaces, which is excessive but just bearable in that example).

Chris C


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

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