How would you make it so when the user hits and key on the keyboard, he's brought to the main function ( int main() )? Need it for a program I'm working on.
How would you make it so when the user hits and key on the keyboard, he's brought to the main function ( int main() )? Need it for a program I'm working on.
There isn't any universally good way to do this, although it can be done, depending on the program.
One way would be to make it so that every function call that takes you away from main, you call like...
if (imAFunction () == -1) return -1;
Also, for the point at which you want to escape to main by hitting a key,
if (hitkey()) return -1;
The hitkey function you'll have to replace by checking into your compilers documentation... especially take note to look for bios functions, or keyboard functions.
Callou collei we'll code the way
Of prime numbers and pings!
How about reading the input from "any key" and then testing it with an 'if' statement. If it is '/n' for instance, return to main(), if not (ie 'else') return to main() aswell.
Just a thought.