Link to home
Start Free TrialLog in
Avatar of Benjamin_Barrett
Benjamin_Barrett

asked on

Calling main() within main()

Following on from my question here

https://www.experts-exchange.com/questions/21925676/Using-'enter'-to-return.html


How can I get my program to return to the main menu, without calling main()?

I do this elsewhere in the program, but always within other functions that main has called....
ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
being more elaborate
do
{
       print (option a)
       print (option b)
       ...
       print (option n)
       read (user_option)
       if (user_option was "\n" )
              continue
       switch (user_option)
       {
             case option a:
                        ....
             case option b:
                       ....
             case option n:
                       ...
             default:
                 print unknown option
}while (user_option was not quit)
Avatar of Benjamin_Barrett
Benjamin_Barrett

ASKER

OK...

wouldnt the do loop be inside the switch statement?

ie switch(option)
        case '1'
             printf("Enter a string (1-5 characters): ");
            fgets
             do
             {
            stuff
             }while(!NULL)
           
Sorry, meeting back in 1/2 hour
> wouldnt the do loop be inside the switch statement?

nop. Then then you will need loops inside each case. Also you will not be able to ask for options.

Sunny's idea would be the best.

regards
Manish Regmi
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
With a rewrite I managed this working nicely.

Thanks heaps for your help guys

Benjamin