Thread: Making text menus

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    114

    Making text menus

    Hi I need to do a text menu for my program. I know that I could just use printf, fgets and sscanf but there are a few problems.

    Say if I want 1 digit from the user to use as their choice in the menu I can do it but the user can type as much as he wants untill he presses enter. Everything but the first digit is ignored but I still think its unprofesional. I would like the program to instantly take the number he pressed right away, withought having to press enter first.

    Also I would like to be able to display things as the user is typing things sometimes.

    Anyone have an idea? Thanks

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    This is OS and compiler specific. There is no standard way to read a keystroke. Also, if you're just reading single keystrokes, why can't you wait till that single action has taken place to display something. It's not as if it actually takes any significant time to press a key.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User
    Join Date
    May 2004
    Posts
    114
    Thanks getch() seems to work with my compiler (Sorry for not reading that faq). I wont worry about the blocking text input for the things more than one character because it doesn't matter too much.

    Now the idea of this sniplet is it will take a 1 character input and if its not a number 0 - 6 it spits it back. It doesn't work though

    Code:
    while (choice = getch() > 6 || !isdigit(choice))
        printf ("Woops, '%d' isn't a valid choice\n", choice);
    
    printf("You chose: %d\n", choice);
    It says X isn't a valid choice no matter what you type, even if it is.

    Thanks
    Last edited by kzar; 03-30-2005 at 11:06 AM.

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Code:
    while ((choice = getch()) > '6' || !isdigit(choice))
        printf ("Woops, '%c' isn't a valid choice\n", choice);
    
    printf("You chose: %c\n", choice);
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Registered User
    Join Date
    May 2004
    Posts
    114
    Quote Originally Posted by Dave_Sinkula
    Code:
    while ((choice = getch()) > '6' || !isdigit(choice))
        printf ("Woops, '%c' isn't a valid choice\n", choice);
    
    printf("You chose: %c\n", choice);
    Thanks, works great.

  7. #7
    Registered User
    Join Date
    May 2004
    Posts
    114
    Incase anyone is interested I found a way to use curses on dev-c++ at this page: http://devpaks.org/show.php?devpak=7 .

    edit: I have found a good tutorial here: http://en.tldp.org/HOWTO/NCURSES-Pro...elloworld.html
    Last edited by kzar; 03-31-2005 at 09:44 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making a unicode text file
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 02-15-2008, 08:21 PM
  2. Having trouble making a function do what I want.
    By Shamino in forum C++ Programming
    Replies: 9
    Last Post: 12-07-2007, 11:20 AM
  3. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 03:17 PM
  4. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM
  5. Making a text editor
    By neandrake in forum C++ Programming
    Replies: 5
    Last Post: 02-26-2002, 11:43 PM