开发者

fopen for reading/writing multiple files in a folder C

I have a question about how to use fopen() to read/write multiple files of one folder. I have 100 text files in a folder and I want to use a loop to open all the files (one by one) and write something in them. For example something like this:

for(i = 0; i < 100; i++)
{
  f = fopen("files","a");
  fwrite("hello");
  fclose(f);
}

So for example if i have 100 txt files in the folder "C:\Users\Desktop\examples\txts" I want to open all of them and write for example the same word "hello" to all of them.

If I use it like: "C:\Users\Desktop\examples\txts*开发者_如何学Go.txt" (with the star: *) it doesn't work. Any idas?


You could use readdir, as in this example:

http://www.gnu.org/s/hello/manual/libc/Simple-Directory-Lister.html


You can use the FindFirstFile/FindNextFile api functions on windows, not sure if there's a built in function to do this in C (it's been 20 years (almost) since I wrote real world code in C)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜