开发者

How do I read from severals files in C?

I am working on a program which have to read from txt files. I know that there's a function called fopen("myfile.txt","rt"), but what if I have 10 files? Do i need to call the function 10 times (a call for ev开发者_如何学Cery file)?


Yes. But if you perform the same routines on each of those functions, abstract that behaviour into a function that accepts the name of a file. Now call that function 10 times, once with each file name.

void read_from_text_file(char const *filepath);

read_from_text_file("myfile.txt");
read_from_text_file("myfile2.txt");
...

This is a core concept in computer science. Buzzwords include "abstraction", "routine", "reusability", etc.


Yes. One function call per file is needed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜