Passing a file through a translation unit - scoped variable (i.e. a static FILE *
) is acceptable. However, it leaves some doubts as to who is responsible for calling fclose
. A better approach would be to have the function that opens the file return FILE*
to the caller, with the assumption that the caller would later call fclose
.
Better yet, let the function that calls fread
also do the fopen
: instead of opening the file, the first function could prepare the file name, and store it in a static
variable. Then the reading function could call fopen
, do fread
s, and call fclose
all in a single function.