Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing File i/o to a function

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi there,
I am writing this program for a uni assignment and i need a function to display some student details in a file.

i have opened the file at the start of the program

FILE *fpout;
fpout = fopen("c:\\sp3work\\proj2out.dat","w");
if (fpout == NULL)
printf("error opening file %p\n",fpout)

and then i can display the values it picks up with

fprintf(fpout,"\n\n %-5d %7s %14s %17c%8c %9.2f %12.2f",id_num,given_name,family_name,course_code,shift_code,balance,fee_paid);

But how do i make this same line in a function...i have trouble passing the value of fpout. I have tried passing the pointer value.... in the function def *fpout then in the call &fpout . It is giving me the error 'Cannot convert 'std::FILE *' to 'std::FILE''

I dont want to reopen the file in the function as i cannot let the file pointer be reset as i need it to keep reading the 100 lines of data..

hope this is enough info for some help which would be greatly appreciated..

thanks dave.
 
/*function implementation*/
void openfilefunc(FILE** ppf, char* path)
{
*ppf = fopen(path,"w");
if (fpout == NULL)
printf("error opening file %p\n",fpout)
}
/*using fuction*/
FILE* x;
openfilefunc(&x,"c:\\sp3work\\proj2out.dat");
John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top