M
Mike Copeland
I'm curious about the best way to handle a file which is opened and
closed repeatedly throughout a program's execution. A file (FILE *pfv1)
is used to write one or more different files during the program's
execution, and it can be opened and closed many times - with different
file names.
My question involves the advisability of setting the file variable to
NULL each time it's closed, as well as using that condition to dictate
subsequent open processing. My guess is that doing so will proliferate
multiple instances of the file structure as each open is executed (and
wasting runtime memory), whereas _not_ assigning it a NULL address will
reuse the structure during the multiple opens (for a different file's
processing). Is this true?
Note that each open/write/close sequence is discrete and file-
specific. During processing the program may well detect that the output
file exists and will offer the user option of appending to or
overwriting the file's content.
In summary, I want to be able to use a single file multiple times for
writing content to different files, because the logic to write data is
not specific to the output file(s) being produced.
Please advise. TIA
closed repeatedly throughout a program's execution. A file (FILE *pfv1)
is used to write one or more different files during the program's
execution, and it can be opened and closed many times - with different
file names.
My question involves the advisability of setting the file variable to
NULL each time it's closed, as well as using that condition to dictate
subsequent open processing. My guess is that doing so will proliferate
multiple instances of the file structure as each open is executed (and
wasting runtime memory), whereas _not_ assigning it a NULL address will
reuse the structure during the multiple opens (for a different file's
processing). Is this true?
Note that each open/write/close sequence is discrete and file-
specific. During processing the program may well detect that the output
file exists and will offer the user option of appending to or
overwriting the file's content.
In summary, I want to be able to use a single file multiple times for
writing content to different files, because the logic to write data is
not specific to the output file(s) being produced.
Please advise. TIA