Input that does not display on screen

This is a discussion on Input that does not display on screen within the C++ Programming forums, part of the General Programming Boards category; I know i should not be asking this and that i would prlly be able to find the answera almost ...

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    87

    Input that does not display on screen

    I know i should not be asking this and that i would prlly be able to find the answera almost anywhere if i took the trouble to look but i won't. I would like to know if there is a way to get input from the keyboard without getting it displayed on the screen using console programing.

    Thnx in advance

  2. #2
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    Use getch() in a loop... It will not echo to the screen.. If you use getche() it will...




    if you want to accept chars till enter is pressed without displaying on the screen...

    Code:
    # include <iostream.h>
    
    
    
    int main()
    {
    
    char ch;
    char array[1000];
    int i=0;
    while(ch!=13)
    {
    ch=getch();
    if(ch!=13)
      {
    array[i]=ch;
    i++;
      }
    
    if(i>=1000)
    ch=13;
    }
    
    
    return 0;
    }

    so now the array[] will hold all the chars... There is a better way of doing this... For example now if you press back space, del etc it will also be taken as a char and stored in the array... You need more conditional statement to make this work perfect...
    Last edited by vasanth; 01-15-2003 at 09:06 AM.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>find the answera almost anywhere if i took the trouble to look but i won't.
    Then why should we bother helping you if you won't help yourself.

    Anyway, your question is OS/compiler specific, meaning vasanth's code isn't guaranteed to work for you.

    @vasanth: I'd suggest not using 13, instead use the character constant equivalent. Also, the code creates a buffer overflow
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    yes you are right about it... The buffer needs to be flushed now and then if it is a very long output...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  2. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 04:42 PM
  3. Replies: 2
    Last Post: 12-29-2005, 04:01 PM
  4. Replies: 1
    Last Post: 04-09-2003, 12:39 AM
  5. Replies: 1
    Last Post: 04-01-2002, 03:08 PM

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