Is it possible to call the main() function from within it?
---or---
to call it from another function defined outside of it?
<---- Pritin
Is it possible to call the main() function from within it?
---or---
to call it from another function defined outside of it?
<---- Pritin
nope, (correct me if I'm wrong anyone) I dont think you can just "call" the main function. but you can add parameters and pass it parameters when you execute the program or run it from a script.
In the 1989 C standard, calling main() is allowed. In C++, it is explicitly forbidden. I'm not sure offhand about what the 1999 C standard says, but suspect it would allow calling main().
Code:int MyMain() { if(whatever) { MyMain(); } } int main() { MyMain(); }
The code by "Fordy" I can understand, .. i know that just any function can be called from within it, but what about main()?
I thought of one method, that is by putting the whole of main() in a do while sequence, and if required to repeat, main() can be somewhat"called" again... That's one way i need ed to use it...
But what if I want to to call main() freom another function??
The exact way i want to implement it, is for a very simple that can perform calculations on the eqns of motion... There is an error() function to display errors, but i want it to redirect to main() after displaying errors, which i want to do.... fxns are defined before main()
If calling main is illegal in the version/fork of C you're using, then use fordy's example -- just use main as a wrapper of your "real" main function.
Oh... now i get it... Great. Thanks everyone!! <A HAPPY FACE>