I need to show *** insteed of charecture while input

hello.
this is my code which i am trying to work on

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
int main()
{	
        int tries = 3;
	string acc,password,MainPage,dummy;
	


	{
	while (tries)
	{
	cout <<"Please Enter ID: \a";
	cin >> acc;
	cout <<"Please Enter Password: ";
	cin >> password;


	system("CLS");

	if (acc == ("abc") && password == ("123"))
	{
		goto MainPage;
	}
	else 
	{
		cout << "Invalid Id or Password. Please enter again" <<endl;
		cout << "The Program Will terminate After (" <<tries<< "\n" << ") Unsuccessful Try" <<endl;
		tries--;
	}
	}
	return -1;
}


ignore the problem with {}. because its a pretty big code and they are needed there ( i think)

now for my output it shows like this

Please Enter ID:abc
Please Enter Password:123

but i want the password to show as ***
thank you in advance
No way to do this in standard C++. There are some nonstandard functions that do something like that (or at least something similar) though (I believe you can do this with ncurses, and if your compiler has conio.h you could probably do something similar with that).
well my compiler has conio.h . do u know how to do that. am really new in this . so if u know please tell me in details that a new c++ user can understand :D
Well, 2 things:
1) If I was you, I would just not do stuff like that. You can easily do that in GUI applications, consoles aren't exactly cut out for that kind of task.
2) Focus on learning the language first, before you get into puny details such as that. Start by removing unnecessary system's and goto's (which means, in most cases, ALL system's and goto's).
well for ur 1st statement .
i donot want to do any thing with c++. and this is my project for adding,deleting, showing , updating records. I had a great program that could do all those stuffs but my lecturer ask me to get more functions ( like that ) so i have work on in.
2nd statement .
i realized now that i should have pay attention when my lecturer was teaching the language. but now its too late i have to submit this project and donot have enough time to learn in details.
and the goto there i cannot go to mainpage ( the selection page without it ).

and i have a question now
1
2
3
4
5
6
7
8
			cout << "Invoice no : ";
			//getline(cin,dummy);
			cin.getline (Book.invoice, sizeof(Book.invoice));
			while (strcspn(Book.invoice,"qwertyuiopasdfghjklzxcvbnm1234567890") != NULL)
			{
				cout << "Invalid input! Please enter again! Invoice No.: ";
				cin.getline (Book.invoice, sizeof(Book.invoice));
			}

invoice is char in struct . how can i restrict its minimum value ?
and the goto there i cannot go to mainpage ( the selection page without it ).

What if I say you can?

how can i restrict its minimum value ?

Excuse me? I do not understand what you mean by that. Maybe minimum length? If you are already using cstring functions, you could use strlen.
thank you for the length i got it now.

and i cannot go to main page without it and i know that people can go without it .
now back to my main question
i saw people making the *** thing with their codes . but my problem is i do not have any passget(). i just entered the password so that i do not have to go through all the functions.( and my lecturer said its ok while it can work) so now how can i do it
i got this code on another web but i cannot get it working
1
2
3
4
5
6
7
8
9
10
char Text[255];

while(Text[i]!=13)	//checks whether 'Enter' key is pressed
{					 //The value of Enter key is 13		  
	i++;
	Text[i]=getch();
	printf("*");
}


and i cannot go to main page without it and i know that people can go without it .

Why?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
char Text[255];
memset(Text, 0, 255);
for(int i=0; i<254; ++i)
{
     char c;
     c=getch();
     if(c==13)
     {
          break;
     }  else
     {
           Text[i]=c;
           cout<<"*";
           
      }
}


I think that should work. Didn't try it myself though. Btw: If you enter backspace it won't work as you'd expect it to.
i don get that code can u explain a bit .
What part do you not understand? I can hardly get much more basic than that.
actually i cannot match it with my code . i have no idea which one of this can go with my password
That's the code for entering a password. In that code, Text is the password that is being entered, and after the loop you have a ready-to-use cstring in Text.
so whats the password again ?
sorry i am really new to this i did not get what u mean by ready-to-use cstring in text :S
Topic archived. No new replies allowed.