We help IT Professionals succeed at work.

flusing the buffer after a input..

sduong
sduong asked
on
I'm trying to input something from stdin store it into a char but at the same time I don't want what I type to show up on the screen.. How would I go about doing that..

For example.. if the user types abc.. I want to store the data into a char array.. yet I don't want what they type to show up on the screen......



Comment
Watch Question

if you have _getch() available to you, you can do something like this

#include <conio.h>

void main(void)
{
     while (_getch() != 0x0d)
          {
          }
}
Here's a slightly enhanced example:
#include <stdio.h>
#include <conio.h>

void main(void)
{
     auto     char     cChar=0;
     auto     char     strPassword[16]="";
     auto     int     intCharCount=0;

     puts("Enter password");
     
     while (0x0d != (cChar = (char)_getch()) && intCharCount < (sizeof(strPassword)-1))
          {
          strPassword[intCharCount]=cChar;
          intCharCount++;
          }
     strPassword[intCharCount]='\0';
     puts(strPassword);
}

Author

Commented:
I don't seen to have the conio.h file in my system..Is there another way to do it without this include??
What OS and compiler are you using?
Can you just use getch() instead of _getch()?

Author

Commented:
I'm using Linux Mandrake 8.0...getch don't seem to want to work either....
ozo
SILVER EXPERT
Most Valuable Expert 2014
Top Expert 2015

Commented:
#include <stdlib.h>
char *getpass (const char *prompt);

obg

Commented:
Or look up ncurses man pages. You have a getch in there (among other useful stuff).
Per recommendation comment force/accepted by

Netminder
Community Support Moderator
Experts Exchange

Explore More ContentExplore courses, solutions, and other research materials related to this topic.