CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2009
    Posts
    20

    Exclamation How To Return to Main()

    i have so many functions in my program,what i want to do is, i want to return back to the main() but in somewhere middle of it!.

    should i use goto statements?
    i tried 'em,it gave some error!

    if i should use goto then please explain how to,thanks

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: How To Return to Main()

    You should design your program so that this isn't necessary, that's how.

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: How To Return to Main()

    When you return from a function, control returns to the statement right after your call to the function. So, if you call a function from main, you'll return there.

  4. #4
    Join Date
    Mar 2009
    Posts
    20

    Re: How To Return to Main()

    i want to return to the lines above ,where i call the function,i cant design my program.
    i want to return to a menu which is in the main and if the user wants to run the function again then he can select it again from the main

  5. #5
    Join Date
    Aug 2007
    Posts
    858

    Re: How To Return to Main()

    Quote Originally Posted by arshad115 View Post
    i want to return to the lines above ,where i call the function,i cant design my program.
    i want to return to a menu which is in the main and if the user wants to run the function again then he can select it again from the main
    Basically do something like:

    Code:
    int main( )
    {
      bool shutdown = false;
      while (!shutdown)
      {
        switch (ShowMenuFunction( )) // returns the selected menu option
        {
        case 0:
          DoMenuOptionZeroFunction( );
          break;
    
        case 1:
          DoMenuOptionOneFunction( );
          break;
    
        case N: // assuming option N is 'exit'
          shutdown = true;
          break;
        };
      }
    
      return 0;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured