Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

CsRookie

macrumors newbie
Original poster
Apr 13, 2011
17
0
How would one go about creating a menu for a c program? The menu would allow the user to select where they want to go in the program. For example:

1)View Inventory
2)Add Inventory
3)Remove Inventory
4)Save
5)Exit

Something along those lines and the user would input 1-5 and then it would take them to the next part of the program. How would a menu driven program work? I tried the search but no luck, any links to examples or simple explanation would be greatly appreciated. :apple:
 
Last edited:
Something like the following pseudo-code:

Code:
Initialize program
Loop
  Print menu on screen
  Read menu choice from keyboard
  If menu choice is 1 then do view inventory
  If menu choice is 2 then do add inventory
  (etc.)
  If menu choice is 5 then exit loop
End loop
Cleanup program

In terms of implementing this, you'd probably do this all in main, and define separate functions to implement "do view inventory", "do add inventory", etc.
 
Something like the following pseudo-code:

Code:
Initialize program
Loop
  Print menu on screen
  Read menu choice from keyboard
  If menu choice is 1 then do view inventory
  If menu choice is 2 then do add inventory
  (etc.)
  If menu choice is 5 then exit loop
End loop
Cleanup program

In terms of implementing this, you'd probably do this all in main, and define separate functions to implement "do view inventory", "do add inventory", etc.

Thanks for the quick response, I thought it may be a loop but wasn't sure. Thank you again :apple:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.