Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 21st, 2004, 09:11 AM
Authorized User
 
Join Date: Jan 2004
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default c++ question

hello....i want to know the logic of the following question..
ok....i would like to write a program..that asks the user to enter his email address.....and enter his password...." when the user enters the password" it should be in the form of *******...then i would like to make the program shows the ****** in letters..

example: sample output

Enter your email.
name@name.com
Enter your password.
********

thanks
Your password is : name123

Reply With Quote
  #2 (permalink)  
Old February 24th, 2004, 03:35 AM
Registered User
 
Join Date: Feb 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Check the implementation for yor problem. The length of the UserName and Password are restricted to 10, but you may change it as you wish.

#include <stdio.h>
#include <conio.h>
main()
{
    char UserName[10], Password[10];
    printf("\nEnter User Name :");
    scanf("%s", UserName);
    printf("\nEnter Password :");
    char ch; int i=0;
    while((ch=getch())!=13)
    {
        Password[i] = ch;
        putch('*');
        i++;
    }
    Password[i] = '\0';

    printf("\nThanks\nYour Password is :%s\n", Password);
}

Venkat
Reply With Quote
  #3 (permalink)  
Old February 24th, 2004, 12:20 PM
Authorized User
 
Join Date: Jan 2004
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello........please can you explain for me the step of the while statement...i got confused with that..

and thank for helping..i appreciate it

Reply With Quote
  #4 (permalink)  
Old February 24th, 2004, 02:45 PM
Friend of Wrox
 
Join Date: Feb 2004
Location: Bangalore, Karnataka, India.
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
Default

While loop runs until you press the enter key, ASCII equivalent of enter key is 13.

Whenever you press a key in the keyboard it is stored in the variable ch, which is not echoed on the screen, because the function getch() won't display on the screen.

But we have putch('*') which will put * on the scree, for each key you are pressing.

Finally outside the while loop, you add the null character to end the string.

Regards
Pradeep

It is not how much we do,
but how much love we put in the doing.

-Mother Theresa
Reply With Quote


Similar Threads
Thread Thread Starter Forum Replies Last Post
question maheshraju ASP.NET 2.0 Basics 3 March 13th, 2008 08:54 AM
Question Ashwini Classic ASP Databases 3 January 10th, 2006 07:20 AM
Question? Calibus Classic ASP Databases 8 August 6th, 2004 08:25 AM
a question gorji C++ Programming 2 August 11th, 2003 07:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.