-   Programming (
-   -   passing a file handle as a parameter in c (

nkoplm 02-05-2008 07:54 PM

passing a file handle as a parameter in c
say i have

        FILE *fhandle;
        fhandle = fopen (argv[1],"w");

how do i pass that file handle into a function? and more importantly, how do i write the function signature that will properly accept the file handle? what data type do i give it?

hope this makes sense :)

jlinkels 02-05-2008 08:04 PM

My c is a bit rusty, but why not use the type FILE:

FILE *fhandle;

int my_function (FILE *my_file_handle){

fhandle = fopen (argv[1],"w");
my_function (fhandle);

nkoplm 02-05-2008 08:28 PM

haha oh boy.
i had tried that... it would be the intuitive answer after all... but it just gave me a compiler error... Of course now that i am trying to reproduce the error it is working perfectly. who knows what went wrong the first time. thanks for the reply :P

All times are GMT -5. The time now is 08:42 PM.