making a VERY simple menu

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tricard@gmail.com

    #1

    making a VERY simple menu

    Good evening,

    I was thinking about making a very simple DOS based (console) menu for
    a project that i am working on, but I have no idea where to start for
    something like this. Does anyone have any resources they could point me
    to or shed some light on what it is that you do exactly. Like I said, I
    don't want a real complicated menu, just a title and about three
    options. I will add more stuff once I know what it is that I am doing.

    thanks in advance

    Tim

  • Ulrich Eckhardt

    #2
    Re: making a VERY simple menu

    tricard@gmail.c om wrote:[color=blue]
    > I was thinking about making a very simple DOS based (console) menu for
    > a project that i am working on, but I have no idea where to start for
    > something like this. Does anyone have any resources they could point me
    > to or shed some light on what it is that you do exactly. Like I said, I
    > don't want a real complicated menu, just a title and about three
    > options. I will add more stuff once I know what it is that I am doing.[/color]

    Print options using printf(). Input the user's choice using scanf(). Don't
    forget to check for errors in the input part. Repeat until you have a
    valid choice.

    Just try it, it's really simple.

    Uli

    Comment

    • Michael Mair

      #3
      Re: making a VERY simple menu

      tricard@gmail.c om wrote:[color=blue]
      > Good evening,
      >
      > I was thinking about making a very simple DOS based (console) menu for
      > a project that i am working on, but I have no idea where to start for
      > something like this. Does anyone have any resources they could point me
      > to or shed some light on what it is that you do exactly. Like I said, I
      > don't want a real complicated menu, just a title and about three
      > options. I will add more stuff once I know what it is that I am doing.[/color]

      Depends. If you want fancy stuff using arrow keys etc.,
      then you are wrong here as we discuss only standard C.
      A newsgroup discussing DOS will probably be able to point
      you in the right direction.
      If you stick with standard C, you can do something along
      the lines
      do {
      /* Output options */
      fflush(stdout);
      /* Read in the reply, do not use *scanf() see clc faq */
      /* variant a) safe user choice */
      } while (!validchoice);
      /* a) dispatch according to choice*/
      or
      do {
      /* Output options */
      fflush(stdout);
      /* Read in the reply, do not use *scanf() see clc faq */
      /* variant b) dispatch according to non-exit choice */
      } while (!exitmenu);

      Cheers
      Michael
      --
      E-Mail: Mine is an /at/ gmx /dot/ de address.

      Comment

      • Vladimir S. Oka

        #4
        Re: making a VERY simple menu

        Ulrich Eckhardt wrote:
        [color=blue]
        > tricard@gmail.c om wrote:[color=green]
        >> I was thinking about making a very simple DOS based (console) menu
        >> for a project that i am working on, but I have no idea where to start
        >> for something like this. Does anyone have any resources they could
        >> point me to or shed some light on what it is that you do exactly.
        >> Like I said, I don't want a real complicated menu, just a title and
        >> about three options. I will add more stuff once I know what it is
        >> that I am doing.[/color]
        >
        > Print options using printf(). Input the user's choice using scanf().
        > Don't forget to check for errors in the input part. Repeat until you
        > have a valid choice.[/color]

        I'd suggest to use printf()/fgets()/sscanf() instead, just to be on the
        safe side (NOT gets()), and /do/ check for invalid input.
        [color=blue]
        > Just try it, it's really simple.[/color]

        I concur.

        Cheers

        Vladimir

        --
        You know you've landed gear-up when it takes full power to taxi.

        Comment

        • Tim Ricard

          #5
          Re: making a VERY simple menu

          Thanks for the help. Okay, so just one question then, just so I know if
          this is a standard C question or not. What if I want some items to be
          static on the screen (like at the bottom have "press F3 for help"
          etc.)? Is this a standard C question or more specific to a DOS C group?

          Tim

          Comment

          • osmium

            #6
            Re: making a VERY simple menu

            "Tim Ricard" wrote:
            [color=blue]
            > Thanks for the help. Okay, so just one question then, just so I know if
            > this is a standard C question or not. What if I want some items to be
            > static on the screen (like at the bottom have "press F3 for help"
            > etc.)? Is this a standard C question or more specific to a DOS C group?[/color]

            No, function keys and their mere existence are outside the scope of standard
            C.


            Comment

            • Vladimir S. Oka

              #7
              Re: making a VERY simple menu

              Please quote what you reply to...

              Tim Ricard wrote:[color=blue]
              > Thanks for the help. Okay, so just one question then, just so I know if
              > this is a standard C question or not. What if I want some items to be
              > static on the screen (like at the bottom have "press F3 for help"
              > etc.)? Is this a standard C question or more specific to a DOS C group?
              >
              > Tim[/color]

              Standard C does not know anytrhing about the "screen". ;-)

              What I'd suggest, if you wanted 100% standard C and portability, is to
              simulate celaring the screen by outputing /many/ blank lines when
              re-drawing the menu. Scrolling may just send the old menu off the
              screen. You'll never know how many is enough for any given machine, but
              at least the old menu will be far away from the new.

              Otherwise, ask about your specific platform in appropriate group. You
              mention DOS, so comp.os.msdos.p rogrammer may be the right place.

              Cheers

              Vladimir

              Comment

              • CBFalconer

                #8
                Re: making a VERY simple menu

                Tim Ricard wrote:[color=blue]
                >
                > Thanks for the help. Okay, so just one question then, just so I know if
                > this is a standard C question or not. What if I want some items to be
                > static on the screen (like at the bottom have "press F3 for help"
                > etc.)? Is this a standard C question or more specific to a DOS C group?[/color]

                It's not. There is no mention of 'screen' in the C standard.

                Please include adequate context. See below for how on the broken
                google interface to usenet.

                --
                "If you want to post a followup via groups.google.c om, don't use
                the broken "Reply" link at the bottom of the article. Click on
                "show options" at the top of the article, then click on the
                "Reply" at the bottom of the article headers." - Keith Thompson
                More details at: <http://cfaj.freeshell. org/google/>

                Comment

                • Flash Gordon

                  #9
                  Re: making a VERY simple menu

                  Tim Ricard wrote:[color=blue]
                  > Thanks for the help. Okay, so just one question then, just so I know if
                  > this is a standard C question or not. What if I want some items to be
                  > static on the screen (like at the bottom have "press F3 for help"
                  > etc.)? Is this a standard C question or more specific to a DOS C group?[/color]

                  You can't do it in standard C not can you portably detect the F3 key, so
                  you will have to go to a DOS group for this.

                  By the way, asking here if something is possible in standard C is
                  perfectly reasonable even when the answer turns out to be no.
                  --
                  Flash Gordon
                  Living in interesting times.
                  Although my email address says spam, it is real and I read it.

                  Comment

                  • Keith Thompson

                    #10
                    Re: making a VERY simple menu

                    "Vladimir S. Oka" <novine@btopenw orld.com> writes:
                    [...][color=blue]
                    > Standard C does not know anytrhing about the "screen". ;-)
                    >
                    > What I'd suggest, if you wanted 100% standard C and portability, is to
                    > simulate celaring the screen by outputing /many/ blank lines when
                    > re-drawing the menu. Scrolling may just send the old menu off the
                    > screen. You'll never know how many is enough for any given machine, but
                    > at least the old menu will be far away from the new.[/color]

                    Sure, but I think this is one of the cases where 100% standard C just
                    isn't worth the effort. If you really need to clear the screen, I'd
                    say you're better off finding out how to do it on each system you want
                    to support and writing a clear_screen function with however many
                    #ifdefs you need. (You can even resort to printing a bunch of blank
                    lines if all the #ifdefs fail.) The result is going to look a *lot*
                    better.

                    Then again, it's not likely that clearing the screen is going to be
                    the only system-specific think you want to do. If you want to be able
                    to move the cursor to an arbitrary position on the screen, for
                    example, you'll need to use some more system-specific code, which is
                    likely to become a fairly large part of your program.

                    --
                    Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                    We must do something. This is something. Therefore, we must do this.

                    Comment

                    • Brian Dude

                      #11
                      Re: making a VERY simple menu

                      Tim Ricard <tricard@gmail. com> wrote in article
                      <1138114529.206 758.260910@g44g 2000cwa.googleg roups.com>...[color=blue]
                      > Thanks for the help. Okay, so just one question then, just so I know if
                      > this is a standard C question or not. What if I want some items to be
                      > static on the screen (like at the bottom have "press F3 for help"
                      > etc.)? Is this a standard C question or more specific to a DOS C group?
                      >
                      > Tim
                      >[/color]

                      I've often had good luck at:

                      comp.os.msdos.p rogrammer

                      That's where I go when I have questions on DOS console applications,
                      function key access, etc.

                      Good luck!

                      Brian Dude

                      Comment

                      • Emmanuel Delahaye

                        #12
                        Re: making a VERY simple menu

                        tricard@gmail.c om a écrit :[color=blue]
                        > I was thinking about making a very simple DOS based (console) menu for
                        > a project that i am working on, but I have no idea where to start for
                        > something like this. Does anyone have any resources they could point me
                        > to or shed some light on what it is that you do exactly. Like I said, I
                        > don't want a real complicated menu, just a title and about three
                        > options. I will add more stuff once I know what it is that I am doing.[/color]

                        It's quite a simple algorithm:

                        DO
                        printout the options
                        entry an option
                        test the entry
                        execute the corresponding action
                        UNTIL end

                        do your best and post the code if you are stuck.

                        --
                        A+

                        Emmanuel Delahaye

                        Comment

                        • Keith Thompson

                          #13
                          Re: making a VERY simple menu

                          Keith Thompson <kst-u@mib.org> writes:
                          [...][color=blue]
                          > Then again, it's not likely that clearing the screen is going to be
                          > the only system-specific think you want to do. If you want to be able
                          > to move the cursor to an arbitrary position on the screen, for
                          > example, you'll need to use some more system-specific code, which is
                          > likely to become a fairly large part of your program.[/color]

                          And if clearing the screen *is* the only system-specific thing you
                          want to do, pleaes reconsider whether you really need to do that.
                          Clearing my screen for a full-screen text editor is ok; erasing what
                          might be important information just so your program's prompt can be at
                          the top of a blank screen is rude.

                          --
                          Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                          San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                          We must do something. This is something. Therefore, we must do this.

                          Comment

                          • Joe Wright

                            #14
                            Re: making a VERY simple menu

                            Keith Thompson wrote:[color=blue]
                            > Keith Thompson <kst-u@mib.org> writes:
                            > [...]
                            >[color=green]
                            >>Then again, it's not likely that clearing the screen is going to be
                            >>the only system-specific think you want to do. If you want to be able
                            >>to move the cursor to an arbitrary position on the screen, for
                            >>example, you'll need to use some more system-specific code, which is
                            >>likely to become a fairly large part of your program.[/color]
                            >
                            >
                            > And if clearing the screen *is* the only system-specific thing you
                            > want to do, pleaes reconsider whether you really need to do that.
                            > Clearing my screen for a full-screen text editor is ok; erasing what
                            > might be important information just so your program's prompt can be at
                            > the top of a blank screen is rude.
                            >[/color]

                            After a couple of conio.h episodes several years ago, I gave up on CLI
                            stuff altogether. Now I think to take it up again 'portably' using
                            curses. Theoretically the same simple menu could run on Unix, Sun and
                            DOS as well. Although curses is not Standard it is ubiquitous. Is it
                            portable?

                            --
                            Joe Wright
                            "Everything should be made as simple as possible, but not simpler."
                            --- Albert Einstein ---

                            Comment

                            • Robert Gamble

                              #15
                              Re: making a VERY simple menu

                              tricard@gmail.c om wrote:[color=blue]
                              > Good evening,
                              >
                              > I was thinking about making a very simple DOS based (console) menu for
                              > a project that i am working on, but I have no idea where to start for
                              > something like this. Does anyone have any resources they could point me
                              > to or shed some light on what it is that you do exactly. Like I said, I
                              > don't want a real complicated menu, just a title and about three
                              > options. I will add more stuff once I know what it is that I am doing.[/color]

                              Here is a simple example of a menu in Standard C:

                              #include <stdio.h>
                              #include <stdlib.h>

                              int main (void) {
                              int long c = 0;
                              char buf[80];
                              puts("Select an option");
                              puts("1 First option");
                              puts("2 Second option");
                              puts("3 Third option");
                              while (fgets(buf, 100, stdin) != NULL) {
                              c = strtol(buf, NULL, 10);
                              switch (c) {
                              case 1: case 2: case 3:
                              printf("You selected option %ld\n", c);
                              break;
                              default:
                              puts("Invalid option");
                              break;
                              }
                              }
                              return 0;
                              }

                              The only case not explicitly handled is when a user inputs n characters
                              at a time where n is greater than 79, in this case the loop will run
                              n/79+1 times. If this is not what you would like you can drain the
                              input buffer after each call to fgets (there is no standard function
                              specifically for this purpose) or use some scanf magic. Also note that
                              if someone enters "2h", this will behave as if the user entered "2".

                              If you want to do anything fancy like cursor placement, unbuffered
                              non-blocking i/o, colors, etc. you will need to step outside Standard
                              C. In that case you may want to check out ncurses (which is off-topic
                              here so if you have questions about it ask elsewhere).

                              Robert Gamble

                              Comment

                              Working...