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.
精彩评论