Automatic <cr> in User Inteface

This is a discussion on Automatic <cr> in User Inteface within the C Programming forums, part of the General Programming Boards category; Hi all, I have am writing a simple user interface that scans a single keyboard keystroke. I am using scanf ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    5

    Automatic <cr> in User Inteface

    Hi all,
    I have am writing a simple user interface that scans a single keyboard keystroke. I am using scanf ("%s", input); along with a errorchecking function.
    My question is: Does anyone know how to scan in a single user keystroke input without the user hitting <cr> on the keyboard. (Automatic <cr> after a keystroke)

    My interface consists of a several numbered menus, therefore an automatic <cr> will make my user interface flow more smoothly.

    Thanks in advance.
    ~jc

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    9

    Cool No <cr> for input

    Hi chubaka,

    THis question comes up alot when people are learning C. The short answer is: There isn't a good way to do it. When you scan a string or a single character from the keyboard, it isn't actually flushed from the input buffer to your program until the user presses <return>. You should get used to this fact and just have menus where the user has to type <return>.

    The long answer is, it is possible, although vastly more complicated then you probably want to get into if you're a beginner. The "curses" library on UNIX/Linux systems allows for this type of behavior as well as "positive carriage control" meaning that you can print stuff where you want on the terminal screen (For example, updating a clock always at the top-right corner, not always just printing to the next line). See curses.h in your /usr/include directory if you're really eager. Windows programming is entirely different but has a similar library.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    5
    Thanks PopRox...
    I wouldn't say I'm a beginner, nor an advanced C programer. However, I am interested in finding an work around for a windows terminal based interface.

    Can you direct me to the proper Window's Library file. (I'm using MS Visual C (MSVC) )

    Thanks!

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    5
    In addition to MSVC, I'm using a modified GNU complier (gcc)

    ~jc

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 04-03-2008, 09:07 PM
  2. Add/Delete Remotely a user
    By Scarvenger in forum Windows Programming
    Replies: 5
    Last Post: 03-24-2008, 08:36 AM
  3. ~ User Input script help~
    By indy in forum C Programming
    Replies: 4
    Last Post: 12-02-2003, 05:01 AM
  4. Beginner question- user input termination
    By westm2000 in forum C Programming
    Replies: 3
    Last Post: 12-02-2001, 01:48 PM
  5. Stopping a user from typeing.
    By knave in forum C++ Programming
    Replies: 4
    Last Post: 09-10-2001, 12:21 PM

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