Is it possible to use fclose() once for 2 file pointers.
Somewhat like this : fclose(in,out);
please help

Recommended Answers

All 3 Replies

fclose() is declared as int fclose ( FILE * stream );. As you can see it only takes one FILE*. So the answer to your question is no.

but FILE *out , *in is possible

When you write FILE *out , *in you can be translated to FILE *out; FILE* *in. When using , in a function call it is used to separate the paramaters that are being used in the function. With that fclose(in, out) translates to call function fclose that takes 2 FILE pointers. Since that function doesn't exist you get a compiler error. If you really want that functionality you can write your own function template that uses variadic templates that will call fclose() on all of the paramaters in the pack.

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.