Forum Moderators: coopster

Message Too Old, No Replies

changing file pointers before closing them

         

scorpion

9:37 pm on Apr 23, 2003 (gmt 0)

10+ Year Member



is it allowed to do this:

ptr1 = fopen("firstfile");
do some stuff
ptr1 = fopen("secondfile");
do some stuff
ptr1 = fopen("thirdfile");

or do you have to issue an fclose() after each time?

jatar_k

10:05 pm on Apr 23, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I think that you can do that just fine with out closing it. You, obviously, will only be able to access the file the pointer was last pointed at.

It is just like reassigning the values of any type of variable.

grahamstewart

11:08 pm on Apr 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



All open files will be closed automatically when the script finishes.

However, if you have files open for writing then you usually want to close them as soon as possible because (A) that way they are definitely flushed if the script suffers a fatal error and (B) if another user is running the script at the same time, they may be blocked till they can get write access to the file.