Thread: improving input (replacing "cin")

  1. #1

    improving input (replacing "cin")

    is there a way to input values without having to use "Enter"?
    I've heard of getch and cin.get but don't know how to use them. Any advice?

    for example, how can I replace the cin with getch or cin.get?


    int array[10], x;
    //do I do something like cin.get(array[x]); or something?


    also, what is the ASCII code for Backspace, if there is any.

  2. #2
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    #include conio.h
    char KeyInput = getch();

    //at least i think its conio.
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  3. #3
    correction in code:

    for(x=0;x<9;x++) //forgot that it begins at array[0]

  4. #4
    Yeah, you should use getch();. That is better, and it doesn't return the input on the screen unless you print it manually, which is usually a good thing.
    What will people say if they hear that I'm a Jesus freak?
    What will people do if they find that it's true?
    I don't really care if they label me a Jesus freak, there is no disguising the truth!

    Jesus Freak, D.C. Talk


  5. #5
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    even better...

    check if the keyboard buffer has something, and if so, return the scan code and ascii in a short int... [16 bits of space...] else return zero... this way, you get to do other things if no input occurs, since you don't have to wait... plus you get scan and ascii codes so you can do special keyboard presses which aren't mapped in ascii... the scan codes let you use the keyboard's keys more like buttons rather than assigned keys...
    hasafraggin shizigishin oppashigger...

  6. #6
    there seems to be a problem with the following code. when I input the values, the values don't get show up until the loop terminates. why is that? is there a solution to correct this?

    also, how do I change the array to a pointer? when I use "int *array", an error occurs when the loop executes.

    //using MSVC++ 6.0
    int main()

    array[10], //seems like getch() only works with int types
    array[x] = getch();

    {return 0;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. input redirection
    By sashaKap in forum C Programming
    Replies: 6
    Last Post: 06-25-2009, 01:59 AM
  2. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  3. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 11:09 AM
  4. Replacing tabs in the input
    By dineren in forum C Programming
    Replies: 1
    Last Post: 08-22-2003, 05:00 AM
  5. need help with some input
    By blindleaf in forum C Programming
    Replies: 2
    Last Post: 03-16-2003, 01:50 PM