开发者

How do I read from severals files in C?

开发者 https://www.devze.com 2023-01-24 07:44 出处:网络
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 (

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

精彩评论

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

关注公众号