LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   passing a file handle as a parameter in c (http://www.linuxquestions.org/questions/programming-9/passing-a-file-handle-as-a-parameter-in-c-618946/)

nkoplm 02-05-2008 07:54 PM

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

        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:
Code:

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 07:26 AM.