This is just a school level program and I am a C++ n00b. So I would be grateful to people helping me out with this if there is any solution.

CAN I TERMINATE A STRING ENTERED BY --getch();-- WHEN I PRESS THE <ENTER> KEY ??
SEE THE PROGRAM BELOW WHERE I HAVE GIVEN COMMENTS REGARDING MY PROBLEM.

#include<all.h>
void main()
{
clrscr();
char a[21],b[21],c[21];
cout<<"REGISTRATION FORM\n\n";
cout<<"Enter Name : ";
gets(a);
cout<<"Enter Username : ";
gets(b);
cout<<"Enter Password : ";
for(int i=0;i<21;i++)
{
c=getch();
if(c!=':') //I have set the terminating character for the password as ':' ---- I want to
cout<<"*"; //know if i can terminate the string when i press the <enter> key.
else //Currently even if I press the <enter> key a character is accepted . HELP ME!!
{
c='\0';
break;
}
}
cout<<"\n\n\n\Press any key to continue...";
getch();
clrscr();
cout<<"Redirecting to login page...";
delay(6000);
clrscr();
char x[21],y[21];
cout<<"LOGIN \n\n";
cout<<"Enter Username : ";
gets(x);
cout<<"\n";
cout<<"Enter Password : ";
for(i=0;i<21;i++)
{
y=getch();
if(y!=':')
cout<<"*";
else
{
y='\0';
break;
}
}
if(strcmp(b,x)==0 && strcmp(c,y)==0)
{
cout<<"\n\n\nLogging in...";
delay(6000);
clrscr();
for(i=0;i<50;i++)
cout<<" ";
cout<<"Logged in as ";puts(x);
for(i=0;i<10;i++)
cout<<endl<<endl;
cout<<" LOGIN SUCCESS";
getch();
}
else
cout<<"\n\nInvalid username or password";
getch();
}

use this

while((c=getche()!='\r')
{
cout<<"*";
i++;
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.