The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Backspace key reads a character instead of removing password in C++ program
Discuss Backspace key reads a character instead of removing password in C++ program in the C Programming forum on Dev Shed. Backspace key reads a character instead of removing password in C++ program C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 2nd, 2012, 04:15 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 1
Time spent in forums: 23 m 55 sec
Reputation Power: 0
|
|
|
Backspace key reads a character instead of removing password in C++ program
Hello dears,
I've began learning C++ / Object Oriented Programming and am facing a problem in assigning password to my following program,
When I type the password it does not have any problem but when I want to remove a character using backspace or delete keys instead of removing they print characters. Need Your Kind Help!
This is my program coding:
Code:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<dos.h>
class project
{
private:
int i,oop,dld,dbc,ca,eng,total;
float percent;
char name[10]; char fname[10]; char program[4];
public:
void design(void)
{
for(i=0;i<=40;i++)
{
gotoxy(5+i,2);
cout<<"\xdb";
gotoxy(5+i,4) ;
cout<<"\xdb";
gotoxy(5+i,23) ;
cout<<"\xdb";
gotoxy(5+i,25) ;
cout<<"\xdb";
}
for(i=0;i<=22;i++)
{
gotoxy(5,2+i);
cout<<"\xdb";
gotoxy(45,2+i);
cout<<"\xdb";
}
gotoxy(11,3);
cout<<" Detailed Marks Certificate ";
gotoxy(9,24);
cout<<"For Help contact DB Administrator ";
}
void input(void)
{
gotoxy(12,6);
cout<<"1. OOP:";
gotoxy(12,8);
cout<<"2. DLD:";
gotoxy(12,10) ;
cout<<"3. DBC:";
gotoxy(12,12);
cout<<"4. C.Alg:";
gotoxy(30,6);
gotoxy(12,14);
cout<<"5. Eng:";
gotoxy(30,6);
cout<<"Name:";
gotoxy(30,8);
cout<<"F/Name:";
gotoxy(30,10);
cout<<"Program:";
gotoxy(9,17);
for(i=0;i<=32;i++)
{
cout<<"\xdb";
}
gotoxy(14,18);
cout<<"Total:";
gotoxy(9,19);
cout<<"Percentage:";
gotoxy(14,20);
cout<<"Grade:";
}
void call(void)
{
gotoxy(19,6);
cin>>oop;
gotoxy(19,8);
cin>>dld;
gotoxy(19,10);
cin>>dbc;
gotoxy(21,12);
cin>>ca;
gotoxy(19,14);
cin>>eng;
gotoxy(36,6);
cin>>name;
gotoxy(37,8);
cin>>fname;
gotoxy(39,10);
cin>>program;
total=oop+dld+dbc+ca+eng;
gotoxy(20,18);
cout<<total;
percent=total/5;
gotoxy(20,19);
cout<<percent;
if ((percent<=100)&&(percent>=90))
{
gotoxy(20,20);
cout<<"A";
}
else
{
if((percent<90)&&(percent>=80))
{
gotoxy(20,20);
cout<<"B";
}
else
{
if((percent<80)&&(percent>=70))
{
gotoxy(20,20);
cout<<"C";
}
else
{
if ((percent<70)&&(percent>=50))
{
gotoxy(20,20);
cout<<"D";
}
else
{
gotoxy(20,20);
cout<<"Fail";
}
}
}
}
}
};
void main(void)
{
start:
textbackground(4);
textcolor(7);
clrscr();
gotoxy(30,7);
cout<<"Log_In_Page";
gotoxy(5,9);
cout<<"User_Name:";
gotoxy(5,11);
cout<<"Password:";
char name1[10]={"kardan"};
char name2[10];
char pass1[10]={"google"};
char pass2[10]={""};
gotoxy(15,9);
cin>>name2;
gotoxy(14,11);
int i=0;
char ch;
cout<<pass2;
while((ch=getch())!='\r')
{
if(ch!='\b')
{
putch('x');
pass2[i]=ch;
i++;
}
//gotoxy(13+i,11);
if(getch()==8)
{
gotoxy(13+i,11);
//putch('\0');
pass2[i-1]='\0';
i--;
cout<<'\0';
}
}
if(strcmp(name1,name2)==0 && strcmp(pass1,pass2)==0)
{
textbackground(0);
textcolor(7);
clrscr();
gotoxy(25,15);
cout<<"Loading.....";
int j;
for(j=0;j<=40;j++)
{
gotoxy(10+j,16);
cout<<"\xdb";
delay(100);
}
clrscr();
gotoxy(15,15);
cout<<"Press any key to coontinue..." ;
getch();
clrscr();
project obj;
obj.design();
obj.input();
obj.call();
}
else
{
clrscr();
gotoxy(5,15);
cout<<"\n Invalid Password";
gotoxy(5,18);
cout<<"Try Again";
getch();
goto start;
}
getch();
}
|

December 2nd, 2012, 12:21 PM
|
 |
Contributed User
|
|
|
|
Post your code between [code][/code] tags. NOBODY is going to wade through 200+ lines of crappy code just to find out what you did wrong.
And please make sure you copy from your editor (to get some indentation - we hope), and DO NOT just ctrl-c/ctrl-v the code from post #1.
This is how code should look when posted. Keep pressing "Preview Changes" until you get it right.
Last edited by salem : December 2nd, 2012 at 02:16 PM.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|