Including files at run time

Reply

Join Date: Oct 2006
Posts: 514
Reputation: Jishnu will become famous soon enough Jishnu will become famous soon enough 
Solved Threads: 26
Jishnu's Avatar
Jishnu Jishnu is offline Offline
Posting Pro

Including files at run time

 
0
  #1
Dec 21st, 2007
Hello,

I know this much that I want to include two files in my program. But can I decide which files to include at run time? Is this possible?

Thanks in advance,
-Jishnu.
"You know you're a computer geek when you try to shoo a fly away from the monitor screen with your cursor. That just happened to me. It was scary." - Juuso Heimonen.

"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 241
Reputation: ssharish2005 is on a distinguished road 
Solved Threads: 20
ssharish2005's Avatar
ssharish2005 ssharish2005 is offline Offline
Posting Whiz in Training

Re: Including files at run time

 
0
  #2
Dec 21st, 2007
Cant you use ifndef-else-endif directives?

EDIT: Run time, i wonder you could.

ssharish
Last edited by ssharish2005; Dec 21st, 2007 at 6:23 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Including files at run time

 
0
  #3
Dec 21st, 2007
The simple way is to just compile the whole code, then have some kind of decision in the code, like this.
  1. int main ( ) {
  2. if ( something ) {
  3. program1();
  4. } else {
  5. program2();
  6. }
  7. }

A more complicated way would be to write each separate module as a DLL, then at run-time you can choose which library instance to access.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 241
Reputation: ssharish2005 is on a distinguished road 
Solved Threads: 20
ssharish2005's Avatar
ssharish2005 ssharish2005 is offline Offline
Posting Whiz in Training

Re: Including files at run time

 
0
  #4
Dec 21st, 2007
Salem if that was possible, how can we include the .so file at run time?

ssharish
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 514
Reputation: Jishnu will become famous soon enough Jishnu will become famous soon enough 
Solved Threads: 26
Jishnu's Avatar
Jishnu Jishnu is offline Offline
Posting Pro

Re: Including files at run time

 
0
  #5
Dec 21st, 2007
EDIT: Run time, i wonder you could.
Sorry, I could not understand what you mean.

The simple way is to just compile the whole code, then have some kind of decision in the code, like this.
But inside the functions program1() and program2(), how can I include a file?
"You know you're a computer geek when you try to shoo a fly away from the monitor screen with your cursor. That just happened to me. It was scary." - Juuso Heimonen.

"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,951
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Including files at run time

 
0
  #6
Dec 21st, 2007
What do you mean by "include a file"?

Are you talking about source code?
Or binary data (pictures, music, etc.)?
Or just regular text (ASCII, RTF, etc.)?

How do you want it to be used at runtime? And what difference does it make whether you include one or the other?

Answer these three and we'll have an easier time answering you...

Hope this helps.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,343
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1460
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Including files at run time

 
0
  #7
Dec 21st, 2007
If you want to pass the name of the file to your program at runtime then just add the filename on the command line when you run your program.
c:\myprog.exe file1.txt <Enter>
Then your program can use the arguments to main() to get the filename
  1. int main(int argc, char* argv[])
  2. {
  3. char* filename = 0;
  4. if( argc > 1)
  5. filename = argv[1];
  6. }
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 176
Reputation: dubeyprateek is an unknown quantity at this point 
Solved Threads: 22
dubeyprateek's Avatar
dubeyprateek dubeyprateek is offline Offline
Junior Poster

Re: Including files at run time

 
0
  #8
Dec 21st, 2007
Are you talking about including header files at run time ?
Last edited by dubeyprateek; Dec 21st, 2007 at 9:13 am.
I know I am. Therefore I am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 514
Reputation: Jishnu will become famous soon enough Jishnu will become famous soon enough 
Solved Threads: 26
Jishnu's Avatar
Jishnu Jishnu is offline Offline
Posting Pro

Re: Including files at run time

 
0
  #9
Dec 21st, 2007
The files I want to include are header files. They contain definitions of some functions. I want to specify which definitions are to be used at run time.
Last edited by Jishnu; Dec 21st, 2007 at 10:26 am.
"You know you're a computer geek when you try to shoo a fly away from the monitor screen with your cursor. That just happened to me. It was scary." - Juuso Heimonen.

"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 176
Reputation: dubeyprateek is an unknown quantity at this point 
Solved Threads: 22
dubeyprateek's Avatar
dubeyprateek dubeyprateek is offline Offline
Junior Poster

Re: Including files at run time

 
0
  #10
Dec 21st, 2007
You can only have pre processor directives.
#if
#else

You can not include header file as such during runtime.
They contain definitions of some functions. I want to specify which definitions are to be used at run time.
Header files normally should contain declarations you are going to use in your application.
If you don't have appropriate declarations you are expecting "undeclared identifier"

There are other ways to include code at runtime like load dlls, but to answer your question you cannot include header file as such on the fly.
I know I am. Therefore I am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC