Results 1 to 10 of 10

Thread: how is this done?

  1. #1

    Thread Starter
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    how is this done?

    one some console program you have to enter any option, like a number or y,n and its enclosed in [ ] how is it done?????


    Thanks

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    On a Unix system, just print out a couple of backspace characters (\b) to move the cursor back.

    I still haven't worked out how to get cin to return a single character yet though
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099
    what about something like this

    cin.getline(String, 1, *);

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Nope, can't use wildcards with that.

    I think it needs to go down to the streambuf level Will take a look when I have some time.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    char t;
    cin.read(1, &t);

    Might have to swap the parameters, I dont remember =).

    Z.

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Tried it. It still needs you to hit return afterwards.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Oh, you mean realtime input. =)

    Z.

  8. #8
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    You can probably use getchar() or some other function to know when a key is pressed and then you can check the keyboard buffer to know what key was pressed. Since I haven't programmed for a couple of months, I forgot how to do this...
    Baaaaaaaaah

  9. #9
    Junior Member
    Join Date
    Oct 2002
    Location
    MI
    Posts
    23
    Originally posted by abdul
    You can probably use getchar() or some other function to know when a key is pressed and then you can check the keyboard buffer to know what key was pressed. Since I haven't programmed for a couple of months, I forgot how to do this...
    I believe that getchar() returns the character i gets as input, so you just assign it like this:

    character = getchar();

    Not sure on what arguments you'd need, but you could basically make a loop that gets the char, checks if it's [, then goes on checking each char in the string. I've done this before, it's really simple. I'll try and dig up the code.

  10. #10
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    i had to make something to trap keys for school, it doesn't wait for input, if thats what you're looking for...it uses a thread and then runs getch()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width