读取多个文件 [英] reading multiple files

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

问题描述

有没有办法读取多个文件(超过1000个文件)然后

使用C写入一个输出文件?现在在我的程序中,我的
有一个循环,要求输入文件名并写入输出文件

但这很乏味。想象一下输入1000个文件名...是否有一个

有效的方法来做到这一点?


谢谢

Is there any way to read multiple files (more than 1000 files) and then
write into one single output file using C? Right now in my program, I
have a loop which asks for the filename and writes into the output file
but this is tedious. Imagine typing 1000 filenames...is there a
efficient way to do this??

Thanks

推荐答案

2006年5月24日08:33:51 -0700, le **** **@gmail.com 写道:
On 24 May 2006 08:33:51 -0700, le******@gmail.com wrote:
有没有办法读取多个文件(超过1000个文件)然后
写入一个单独的输出文件用C?现在在我的程序中,我有一个循环,询问文件名并写入输出文件
但这很乏味。想象一下输入1000个文件名......是否有一种有效的方法可以做到这一点?

谢谢
Is there any way to read multiple files (more than 1000 files) and then
write into one single output file using C? Right now in my program, I
have a loop which asks for the filename and writes into the output file
but this is tedious. Imagine typing 1000 filenames...is there a
efficient way to do this??

Thanks




< OFF-主题>

你问,怎么样?

我想到的第一个问题是为什么?

这对于大多数命令

shell的内置设施来说是微不足道的。你想解决什么问题?你为什么要这样做?b $ b使用C?

< / OFF-TOPIC>



<OFF-TOPIC>
You are asking, "how?"
The first question that comes to my mind is "why?"
This is trivial to do with the built in facilities of most command
shells. What problem are you trying to solve? Why do you want to do
it "using C"?
</OFF-TOPIC>


我正在考虑使用C,因为与其他语言相比,我可以在C中做得更好。您能否详细介绍一下内置设施

命令shell来完成这项任务?


Roberto Waltman写道:
I was thinking of using C because I can do better in C compared to
other languages. Could you please brief about the built in facilities
of the command shells to do this task?

Roberto Waltman wrote:
2006年5月24日08:33:51 -0700, le******@gmail.com 写道:
On 24 May 2006 08:33:51 -0700, le******@gmail.com wrote:
有没有办法读取多个文件(超过1000个文件),然后使用C写入一个单独的输出文件?现在在我的程序中,我有一个循环,询问文件名并写入输出文件
但这很乏味。想象一下输入1000个文件名......是否有一种有效的方法可以做到这一点?

谢谢
Is there any way to read multiple files (more than 1000 files) and then
write into one single output file using C? Right now in my program, I
have a loop which asks for the filename and writes into the output file
but this is tedious. Imagine typing 1000 filenames...is there a
efficient way to do this??

Thanks



< OFF-TOPIC> 我想到的第一个问题是为什么?
这对于大多数命令的内置设施来说都是微不足道的。贝壳。你想解决什么问题?你为什么要这样做?使用C>?
< / OFF-TOPIC>



<OFF-TOPIC>
You are asking, "how?"
The first question that comes to my mind is "why?"
This is trivial to do with the built in facilities of most command
shells. What problem are you trying to solve? Why do you want to do
it "using C"?
</OFF-TOPIC>






le******@gmail.com 写道:

#有没有读取多个文件(超过1000个文件)然后

#使用C写入一个输出文件?现在在我的程序中,我有一个循环,要求输入文件名并写入输出文件

#但这很乏味。想象一下输入1000个文件名...是否有一个

#这样做的有效方法?


文件名是fopen是一个(char *)表达式。它可以是一个

字符串常量或其他任何(char *)。例如

打开文件的名称如fwxyzDDD,

int i; for(i = 0; i< 1000; i ++){

static char F [] =" fwxyz%03d";

char f [sizeof F + 3] ;

sprintf(f,F,i);

FILE * fn = fopen(f," r"); if(!fn){perror(fn);继续;}

...

fclose(fn);

}

如果你有列表文件名文件(例如

unix find命令的输出),你可以fgets文件名,并打开

你想要的文件名。


-

SM Ryan http://www.rawbw.com/~wyrmwif/

死亡是生活的担忧。死者,像我一样,

只担心腐烂和死螨。
le******@gmail.com wrote:
# Is there any way to read multiple files (more than 1000 files) and then
# write into one single output file using C? Right now in my program, I
# have a loop which asks for the filename and writes into the output file
# but this is tedious. Imagine typing 1000 filenames...is there a
# efficient way to do this??

The file name is fopen is an (char*) expression. It can be a
string constant or anything else that is (char*). For example
to open the file with names like fwxyzDDD,
int i; for (i=0; i<1000; i++) {
static char F[] = "fwxyz%03d";
char f[sizeof F+3];
sprintf(f,F,i);
FILE *fn = fopen(f,"r"); if (!fn) {perror(fn); continue;}
...
fclose(fn);
}
Or if you have list of file names file (for example the output of
the unix find command), you can fgets the file names, and open
the file name you fgets.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Death is the worry of the living. The dead, like myself,
only worry about decay and necrophiliacs.


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

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