Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

conio.h getch() and a clrscr() equivalent 2

Status
Not open for further replies.

xlogik

Programmer
Dec 9, 2002
1
US
hello. i am working on a program, where i need the user to enter a password, which is then stored to a string. but, i need the password to appear as asteriscks, not as plain text. there is a conio.h function called getch() which enabled me to do this, but only on windows.
under winodows, using the conio.h function getch(), the code would look something like this:
[tt]
#include <iostream>
#include <conio.h>
#include <string>
using namespace std

string input;
int i = 0;
char ch;

while ( (ch = getch()) != '\r' )
{
input.at(i) = ch;
cout << '*';
i++;
}
[/tt]

how could i accomplish the same in UNIX? i am running MacOS X 10.2, and using the free Project Builder dev tools which came with the system. I am also looking for a clrscr() function, that works on UNIX as well.
 
Hi,

Here is the function that I use on Linux to clear the screen. Hope this helps

void clrscr (void) {
printf (&quot;\033[2J&quot;);
printf(&quot;\033[0;0f&quot;);
}

Siva
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top