tags:

views:

53

answers:

3
function()
{
 FILE *ptr;
 ptr = fileopen(file1.txt)
 fprint(ptr, some text) //print to file 1

     if(second file needed)
     {
        ptr = fileopen(file2.txt) //open a second file, assign to same file pointer
        fprint(ptr, some text) //print to file 2  not working here? 

     }

}

EDIT:
Not printing to second file...However, fprint() does not return a negative value.

+3  A: 

Yes you can, however, you should ensure that the first file is closed before doing so.

jer
is that why it is not printing to the second file?
Tommy
@Tommy: That's not why it's not printing to the second file, but there's no way to really tell you what's happening with the write to the second file since the posted example isn't real code. If you post a small snippet of real code that shows the problem, you'll get an answer to your actual problem.
Michael Burr
+2  A: 

You can do that, but the problem is that you've lost a way to access the 1st opened file (even if just to close it).

Michael Burr
good to know, do not need to access again if second file is opened.
Tommy
@Tommy: But the first file should still be closed. Maybe close if just before you open the second files (exactly what you want or need to do might depend on what you might want to happen if the 2nd file open attempt fails).
Michael Burr
+1  A: 

Yes all pointers are simply variables that hold a memory address. At first your pointer holds the first memory address that fileopen (I guess you probably meant fopen though?) returns. You can put a different memory address in it later.

Brian R. Bondy