LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-12-2005, 08:57 PM   #1
blizunt7
Member
 
Registered: Mar 2004
Distribution: Fedora Core 1,2,3, RHEL3,4,5 Ubuntu
Posts: 274

Rep: Reputation: 30
c++ redirect program execution


Hey all,
I have a program, that starts with a menu of options (1-9).
for instance if i choose option 3, it then asks me a series of questions.
Im looking to stop execution of those questions (in the middle, via a special keyword), and return to the main menu.
how can i do this??

Currently i have a keywork "main" and it calls the main fuction, displays the menu, and you can continue from there. HOwever when that exits, the program continues execution where the "main" was called. this cannot happen.

Any ideas??

thanks so much!

Josh
 
Old 09-13-2005, 12:31 AM   #2
hhamid
LQ Newbie
 
Registered: Sep 2005
Location: California
Distribution: Ubuntu
Posts: 17

Rep: Reputation: 0
I am not sure that I got you questions or not;
But I think you should write some thing like this:

while (true)
{

// Give a key from user; i.e. 1-9 or for example 'q' for exiting from the program:

// swith on the readen key if it is not 'q' else break
{
case '1':
// A special functions; Which asks a series of questions
break;

case '2':
// A special functions; Which asks a series of questions
break;
.
.
.

}
}
 
Old 09-13-2005, 01:09 AM   #3
blizunt7
Member
 
Registered: Mar 2004
Distribution: Fedora Core 1,2,3, RHEL3,4,5 Ubuntu
Posts: 274

Original Poster
Rep: Reputation: 30
yes, something like that, however i need a little more logic, each case statement directs to a certain function.

And for instance case 1, will redirect to a newItem function, and ask a series of questions. I need the ability to break in the functions (at any question) and not return execution) and redisplay the main menu, (back to the case statementS)
 
Old 09-13-2005, 02:04 AM   #4
blizunt7
Member
 
Registered: Mar 2004
Distribution: Fedora Core 1,2,3, RHEL3,4,5 Ubuntu
Posts: 274

Original Poster
Rep: Reputation: 30
figure a quick hack.

Using a goto statement, i just goto the last line of the function, and program execution continues there.

thanks anyway
 
Old 09-13-2005, 03:23 AM   #5
hhamid
LQ Newbie
 
Registered: Sep 2005
Location: California
Distribution: Ubuntu
Posts: 17

Rep: Reputation: 0
I really suggest you not to handle it with "goto"! I am sure always there is a better way than a goto; for example here you can return a dummy value and whenever you need to check whether the function exit normally or not check the return value and ...
 
Old 09-13-2005, 11:00 AM   #6
blizunt7
Member
 
Registered: Mar 2004
Distribution: Fedora Core 1,2,3, RHEL3,4,5 Ubuntu
Posts: 274

Original Poster
Rep: Reputation: 30
yes, i understand that, however i cannot wait until the end of the function, i need a way to check after each user input, if we should exit the function or not..
is there an efficient way of doing this??
 
Old 09-13-2005, 12:09 PM   #7
Proud
Senior Member
 
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
When you do your user input checking you want an if invalid/keyword, return(EARLY_TERMINATION_CONSTANT) to get back to the case code, where the return value is checked and if it is EARLY_TERMINATION_CONSTANT, you break and the main menu loop runs again.

Edit: I dont think you should ever call the main function, and also shouldnt use GOTOs.

Last edited by Proud; 09-13-2005 at 12:13 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
paralell program execution vishamr2000 Programming 17 08-28-2005 09:15 AM
execution of one program inside of another microsoft/linux Programming 2 03-18-2005 10:24 AM
Key bindings program (custom pasting, program execution, etc.) jrdioko Linux - Software 2 02-05-2005 09:09 PM
program execution at startup DeeDub Linux - Software 2 09-11-2003 01:25 PM
program execution monitoring imp Linux - General 1 05-26-2002 09:22 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration