Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 02-05-2008, 07:54 PM   #1
Registered: May 2005
Distribution: Fedora
Posts: 92

Rep: Reputation: 15
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
Old 02-05-2008, 08:04 PM   #2
Senior Member
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,487

Rep: Reputation: 627Reputation: 627Reputation: 627Reputation: 627Reputation: 627Reputation: 627
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);
Old 02-05-2008, 08:28 PM   #3
Registered: May 2005
Distribution: Fedora
Posts: 92

Original Poster
Rep: Reputation: 15
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing a custom parameter to the kernel jkoshi Linux - Kernel 11 07-13-2009 11:54 AM
setting up scp alias under bash - parameter passing problem gjr Linux - Newbie 4 06-08-2005 06:38 AM
Passing hash of hashes as a parameter (Perl) rose_bud4201 Programming 8 04-21-2005 07:18 PM
Passing parameter to kernel when booting from floppy NewtoSlack Slackware 1 10-10-2003 08:24 PM
parameter passing mechanisms dhanakom Programming 2 09-01-2003 04:15 PM

All times are GMT -5. The time now is 12:20 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration