开发者

Is this the correct syntax for passing a file pointer by reference?

Is this the correct syntax for passing a file pointer by reference?

Function call: printNew(&fpt);

printNew(FILE **fpt)
{        
   //change to fpt in here kept after function开发者_如何学JAVA exits?
}


No. The correct syntax is

void printNew(FILE *&fpt)
{        
   //change to fpt in here kept after function exits?
}

Your code will only change the local pointer to a FILE pointer. Only changes to *fpt are seen by the caller in your code. If you change it to the above, things are passed by reference and changes are promoted like intended. The corresponding argument is passed as usual

printNew(fpt);


I'd be interested in what you are going to do with that file pointer - the normal things you do on an open pointer are to call functions like fgets() and close it with fclose(), none of which require a reference.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜