How would you save a piece of code in one file in the same project and then execute it in another file?
How would you save a piece of code in one file in the same project and then execute it in another file?
it would help me a lot if I knew how because it would simplify a program that I want to write.
A bit vague but maybe you could use header files???
Well i can foresee that the program would have a lot of if statements so how could i make it to do i such and such then do the sub procedure thingy.
Well, the i such and such thingy has been the subject of much research lately by some of the sharpest minds in programming, and no one has been able to crack its hidden mysteries yet.how could i make it to do i such and such
If you want your program to start-up and run another program - FAQ: Run a program from within a program.
If you want to break-up your program into more than one source file - FAQ: Multiple source files for one program
EDIT -
Or, maybe you just need a regular ol' function(). Everything in C/C++ is done in functions...
Conceptually, a function is much like a sub-routine. When it is finished, the program returns to the line (or statement) following the function-call, and you can execute it as many times as you want, from multiple places throughout the program.
So, typically instead of putting 25 lines of code in brackets following your if-statement, you would call a function that has all of that code in it. When the function ends, program-flow returns back to the main (or calling) function where it left-off. (And, that function can call another function, etc., etc., etc.)
Read through the tutorials before you start trying this. A function can only return one variable. You have to use references or pointers if you want your function to affect more than one variable.
Last edited by DougDbug; 11-08-2005 at 08:36 PM.