Reputation: 34523
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.
Upvotes: 2
Views: 2316
Reputation: 347216
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.
Upvotes: 1
Reputation: 340188
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).
Upvotes: 2
Reputation: 20236
Yes you can, however, you should ensure that the first file is closed before doing so.
Upvotes: 5