Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
Could someone please show me how to pass an active, open file handle to a function? I need to use a function to fprintf a coverpage in a .txt file.

UPDATE from OP:
C#
Is this right?
void printHeading(FILE *outHandle);
void printCoverPage(FILE *outHandle);

int main()
{
      FILE *inFile;
      FILE *outFile;
      printCoverPage(outFile);
      printHeading(outFile);
}
void printHeading(FILE *outHandle)
{
      outHandle = fopen(fileName, "w");
}
void printCoverPage(FILE *outHandle)
{
      outHandle = fopen(fileName, "w");
}
Posted
Updated 2-Mar-11 20:19pm
v2
Comments
Sergey Alexandrovich Kryukov 2-Mar-11 17:58pm    
Why it is a problem? Did you try to do it?
I saw, 3 or more similar questions almost at the same time. What, are you all from the same school getting identical assignments or examination questions?
--SA
brainflex 2-Mar-11 18:16pm    
Yes, my class has 33 students and we all have the same assignment. I read your response but it does not SHOW how to do it.
Albert Holguin 2-Mar-11 18:44pm    
we're not here to do your homework
CPallini 3-Mar-11 3:31am    
Nope it is wrong in many ways. For instance the file pointers are passed as [in] parameters, but you're using them, inside the functions as if they was [out] ones.

1 solution

Rule one: Research.

A very quick search of just this site shows several of the answers give to your classmates. Look at them. They give the answer.

This one spells it out: And the answerer is as new to this site as you are...

Passing a File Handle as a parameter to a function?[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900