When would you open and close files within a function instead of in the main program?
________________________________________

The main program is a function. The question makes no sense. The alternatives: "within a function" instead of "within a function".

You would open / close a file within any function for the same reason that you would open / close a file with the main function, i.e., because you need to read from or write to the file.

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.