Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Jun 28th, 2005, 5:53 PM   #1
Navid
Hobbyist Programmer
 
Navid's Avatar
 
Join Date: Feb 2005
Location: Canada
Posts: 187
Rep Power: 4 Navid is on a distinguished road
Send a message via MSN to Navid
Password Program

This is a program where you input a password, and for each char it prints a *.
But when the user presses backspace, it erases the unechoed char that was inputed, but not the *.

#include <stdio.h>

char pass[10];
int count=0;

int main(void)
{
printf("Enter new password (10 characters max):");

while ( (pass[count++]=getch()) != '\r')
{

if(count > 10)
{
for (count=0; count<10; count++)
{
pass[count] = '\0';
}
printf("\n\nYour password is too long, enter it again:");
count = 0;
continue;
}
else
{
if (pass[count-1] == '\b' && count==1)
{
count=0;
continue;
}
else
{
if (pass[count-1] == '\b')
{
printf("\b");
count -= 2;
}
else
{
printf("*");
}
}
}

}
puts("\n\nYour new password is:");puts(pass);
printf("\n");
system("pause");
return 0;
}

So what should I do so it erases the * when the user presses backspace?
Navid is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:04 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC