LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


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

Rep: Reputation: 15
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
 
Old 02-05-2008, 08:04 PM   #2
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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);
 
Old 02-05-2008, 08:28 PM   #3
nkoplm
Member
 
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
 
  


Reply



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:26 AM.

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