quick question about C Dos text menu pgm i was doing

This is a discussion on quick question about C Dos text menu pgm i was doing within the C Programming forums, part of the General Programming Boards category; Hello all. I dont post much on here, but checked out the FAQs n things. I might look into that ...

  1. #1
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765

    quick question about C Dos text menu pgm i was doing

    Hello all. I dont post much on here, but checked out the FAQs n things. I might look into that displaying graphics in dos matter ( dont know though, not tooooo important of an issue for a leisure program ).

    As i said awhile back im creating a selection menu. It's devided into catagories. I want to know how to jump back to a certain spot in the code ) after running an outside exe.

    example:

    #include < stdio.h >

    int main();
    {
    int mainmenu;
    int submenu;

    printf("Select a pgm\n\n1. defrag\n");
    scanf("%d", &mainmenu);
    switch(mainmenu)
    {
    case 1:
    system("c:\\windows\\defrag.exe");
    system("menu.exe"); /* open menu */
    break;

    default:
    printf("Invalid selection");
    break;
    }
    {
    printf("Choose a pgm\n\n1. scandisk\n2. clean");
    scanf("%d", &submenu);
    switch(submenu)

    case 1:
    system("c:\\windows\\scandskw");
    system(" THIS IS WHAT I NEED ");
    break;

    case 2:
    system("c:\\windows\\diskclean");
    system(" THIS IS WHAT I NEED ");
    break;
    }
    return 0;
    }

    This was a very basic example as i dont want to load up this post with miles of code. Sorry for the long post. You see though, I have a main menu, this menu allows you to choose a program, or, go into a second menu with several programs on it. If the user chooses a pgm from the 2nd menu, after that pgm is done running i want to return them to the 2nd menu and not the entire beginning.

    The pgm im working on is much larger, but i just need the basic idea and then i can put it in.
    The world is waiting. I must leave you now.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,659
    O.K. this is an abstraction, so it doesn't exactly extrapolate to your exact program, but look at these two functions. Now unless your saying that the defrag.exe won't allow you to return to the console screen(if so, seek other's help), then this should work.
    It appears to me you have not made each menu it's own function and I think you'd benifit to do so...

    PHP Code:
    void main_menu(void)
    {

    int main_menu_choice=0;

    printf("1)Do defrag/scandisc/other operations \n"
              "2)Set up user info                                 \n"
              "3)Search Database                               \n"
              "4)Exit                                                 \n\n" 
    );

    scanf("%d", &main_menu_choice);

    switch(
    main_menu_choice)
    {
    case 
    1sub_menu1();
    break;
    case 
    2sub_menu2();
    break;
    case 
    3sub_menu4();
    break;
    default: exit(
    1);
    }
    }  
    //End of main_menu function
     





    void sub_menu1(void)
    {
    int sub_menu_choice=0;

    printf("1)Do defrag                                           \n"
              "2)Do scandisc                                       \n"
              "3)Exit                                               \n\n" 
    );

    scanf("%d", &sub_menu_choice);

    switch(
    sub_menu_choice)
    {
    case 
    1system("c:\\windows\\defrag.exe");
                 
    main_menu();  //<----should return you to the main menu
                 
    break;

    case 
    2system("c:\\windows\\scandisc.exe");
                 
    main_menu();
                 break;

    default: exit(
    1);
    }
    }  
    //End of sub_menu function 
    In other words, getting to a menu is as simple as calling it by the function which encapsulates it. Note also that the users choice variable is declared within the function, not in main. Note also that after encapsulating all of your menus, main looks more like this:

    PHP Code:
    #include <stdio.h>
    #include <stdlib.h>

    //function prototypes go here

    int main(

    main_menu();


    printf("Goodbye!");


    return 
    0;
    }


    /// define functions here 

    This of course simplifies things since calling "main_menu()" you are also providing the means to get to the other menus specified in it's "switch/case" statement...

    I hope that helps a little.
    Last edited by Sebastiani; 09-16-2001 at 09:29 AM.



    ITSA
    Socket Library!

  3. #3
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    Bravo, Sebastiani

    I agree with 100% of what he said. I think that is what Shadow was trying to accomplish.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 09:25 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. ncurses menu question
    By mak2k in forum C Programming
    Replies: 2
    Last Post: 11-07-2006, 02:04 PM
  4. LaTeX Question: Displaying Text and Images
    By Reisswolf in forum Tech Board
    Replies: 0
    Last Post: 06-30-2006, 08:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21