Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    need help with C++

    Well im trying to in c++ get the input but dont echo it to the screen but display * instead, also if the backspace key is pressed then delete an astericks and if there is nothing there, beep at you. Also if you use the arrow keys or space bar it beeps at you and does not work as there can't be spaces in this input

    I was trying to use getch in a loop before the input but I couldn't get that to work so I was thinking I probably need to make a function where I have no clue where to start inorder to make that happen :P

    have this so far

    Code:
          fflush(stdout);
          int z = 0, ch, first;
          char password4[100];
          while ((ch = getch()) && ch != '\n' && ch != '\r'
          && z < sizeof(password4) - 1)
          {
             if (ch == '\b' && z > 0) 
             {
                cout << "\b \b";
                fflush(stdout);
                z--;
                password4[z] = '\0';
             }      
             else
             { 
                if (z == 0 && ch == '\b')
                {
                   if( ch == '\b')
                   {
                      cout << "\a";
                   }                                
                }
                first = 2;
                if ( z > 0 || first == 2 && ch != '\b' )
                {
                   cout << "*";
                   password4[z++] = ch; 
                 }
              }
           }
          cout << "\n\n";
          password4[z] = '\0';
    Last edited by Dladu; 10-19-2007 at 01:19 AM.

  • #2
    Regular Coder
    Join Date
    May 2004
    Location
    New Hampshire, America
    Posts
    246
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Simple, you just use SendKeys() to send a backspace to the screen followed by an asterick. You of course record the typed key beforehand and add it to the end of your password array.


  •  

    Posting Permissions

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