开发者

Can I assign the same file pointer a second file?

开发者 https://www.devze.com 2023-01-06 17:41 出处:网络
function() { FILE *ptr; ptr = fileopen(file1.txt) fprint(ptr, some text) //print to file 1 if(second file needed)
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:

No开发者_如何学JAVAt printing to second file...However, fprint() does not return a negative value.


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


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).


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消