|
-
Jan 19th, 2004, 05:38 PM
#1
Thread Starter
Lively Member
Password Help
So, ive been trying to implement a password into my program. I have done a search through the forums on the weekend and found a great thread, but i cant seem to find it any more . Here is what i remember of it:
Code:
#include<iostream.h>
#include<string.h>
int main()
{
short x=0;
char password[20];
char ch;
cout<<"Enter password: ";
while(ch!=13)
{
ch=getch();
password[x]=ch;
cout<<"*";
x++;
}
password[x]='\0';
cout<<password;
return 0;
}
So when i ran it, it didnt show the *s. Then when it printed out the password, there was a whole bunch of crazy characters in front of the password i typed. Also, for a test, i printed out the length of the string and it was like 24 when i inputted like 3 or 4 characters. I also printed out the x value and it was one more then the number of characters i inputted. it probably got the enter key when i pressed it. How can i fix that?
My question is, how can i make the *s appear on the same line? And why was it printing out the password wrong and the length?
-
Jan 20th, 2004, 07:12 AM
#2
1) <iostream>, not <iostream.h>
2) <string> or <cstring> (depends on what you want), not <string.h>
3) You don't need either file from 2).
4) You need <conio.h> though.
5) You need to flush cout after each character.
6) The additional character is the '\r' that occurs in an "\r\n"-pair as represents a new line in Windows.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|