I have an arbitrary number of files whose names I will know and I want to open them for reading. The important point is that I do not want to open them sequentially using a single file pointer. I need to have them all open at the same time. This suggests using and an array of file pointers, where this is declared to be of dimension N, where N is the maximum number of files I can have open.

A quick trawl of the web has not brought anything up and it's not in my textbooks. Being a relatively infrequent C-programmer, I'm not at all sure about setting up and using arrays of file pointers. What is the declaration syntax and how is it used? (Or is there another/better way to do what I want?)

Recommended Answers

All 3 Replies

If you know how to use arrays, and you know how to use FILE pointers, you know how to use arrays of FILE pointers. There's really nothing tricky about it except for the number of files you can have open at any given time. The FOPEN_MAX macro in stdio.h tells you how many streams are guaranteed to be open simultaneously. Note that this number includes the standard streams that are already open. Size your array accordingly.

That would be the best way. And its declared in the same way as any other array

Thanks folks, I've tried it and it works.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.