| | |
Including files at run time
![]() |
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.
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.
"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
The simple way is to just compile the whole code, then have some kind of decision in the code, like this.
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.
C Syntax (Toggle Plain Text)
int main ( ) { if ( something ) { program1(); } else { program2(); } }
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.
•
•
•
•
EDIT: Run time, i wonder you could.
•
•
•
•
The simple way is to just compile the whole code, then have some kind of decision in the code, like this.
"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.
"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
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.
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.
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.
Then your program can use the arguments to main() to get the filename
c:\myprog.exe file1.txt <Enter> Then your program can use the arguments to main() to get the filename
C Syntax (Toggle Plain Text)
int main(int argc, char* argv[]) { char* filename = 0; if( argc > 1) filename = argv[1]; }
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.
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.
"The only truly secure computer is one buried in concrete, with the power turned off and the network cable cut." - Anonymous.
You can only have pre processor directives.
#if
#else
You can not include header file as such during runtime.
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.
#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.
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.
![]() |
Similar Threads
- functions in header files (C++)
- General Tips for Mac OS X (Mac tips 'n' tweaks)
- can't run ad-aware se (Viruses, Spyware and other Nasties)
- Modem keeps dialling when i open files (Viruses, Spyware and other Nasties)
- Ok, It's Linux time! (Getting Started and Choosing a Distro)
- XP Boot problems due to virus? (Viruses, Spyware and other Nasties)
- Exchange server 2000 problems (Networking Hardware Configuration)
- Need some help plz; ima newb (not sure how to catagorize this particular prob) (C++)
- Norton WMI Update doesn't work (Viruses, Spyware and other Nasties)
- Browser hijacked - returns every time I Start (Viruses, Spyware and other Nasties)
Other Threads in the C Forum
- Previous Thread: execl() to copy a file /bin/cp
- Next Thread: syntax question
| Thread Tools | Search this Thread |
* adobe ansi api array arrays binarysearch calculate centimeter changingto char character cm convert copyanyfile copypdffile createcopyoffile createprocess() csyntax directory dynamic fflush file floatingpointvalidation fork forloop frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hardware highest histogram homework i/o inches intmain() iso km license linked linkedlist linux linuxsegmentationfault list logical_drives loopinsideloop. lowest match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat openwebfoundation pattern pdf performance pointer posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string suggestions test unix urboc user variable voidmain() whythiscodecausesegmentationfault win32api windows.h windowsapi






