A.t.m. *********

This is a discussion on A.t.m. ********* within the C Programming forums, part of the General Programming Boards category; i have a curious question.... Something occurred to me while on an ATM,.. I wish to write a program asking ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    60

    A.t.m. *********

    i have a curious question....

    Something occurred to me while on an ATM,..

    I wish to write a program asking a password...but i was bogged a little with this problem...


    1. A user types "stuff" on the keyboard, and all that displays is a sequence of asterisks "*****"

    2. Then when he presses "Enter", then (I want) the whole stuff that he just typed displays on the screen..

    "stuff" could be numbers, characters or special characters...

    the password comparing is easy,.. but could you advise me with the asterisks,..

    any codes/ideas to share ?

    Oi !!

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Lets see some code.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    60

    ok,... but some problems..

    ok, here's my code.. Its really stupid..

    coz everytime i type some "stuff"... i could see the "stuff" on the screen.. and when i hit enter, that's when i see the asterisks="****"

    it should work the reverse,..
    i type some "stuff" and i wanna see the asterisks, and when i hit enter,. thats when i should see what I just typed...

    stuff could be = could be characters, integers,.. whatever

    Code:
    #include <stdio.h>
    int main(void)
    {
     char str[80];
     int num[80];
     clrscr();
     printf("type anything dude: ");
     while (getchar() != '\n')
     printf("*");
    
    
    
    getch();
    }

    that's all i end up with,... please help !

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718

    Talking

    Code:
    while (getch() != '\n') {
      printf("\b*");
      fflush( stdout );
    }
    Last edited by XSquared; 08-18-2003 at 12:10 PM.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    I just made this. Crude, simple and it works. If it don't work there, take out the underscore in the _getch() call.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    
    void gets_mask(char *str, char mask)
    {
    	while (*str = _getch())
    	{
    		if (*str == 13)
    		{
    			*str = NULL;
    			return;
    		}
    		putch(mask);
    		str++;
    	}
    }
    
    int main()
    {
    	char pw[16];
    	
    	gets_mask(pw, '*');
    	printf("\npw: %s\n", pw);
    
    	printf("\n\n");
    	system("pause");
    	return 0;
    }

  6. #6
    Registered User
    Join Date
    Jun 2003
    Posts
    60

    sorry couldn't follow....

    sorry, but i couldn't follow....

    im trying and analyzing using:
    Code:
    if (isalnum(ch))
        {
          printf('*');
         }
    i'll understand this thing soon....

    but at the moment im listing my theories...


    p.s: thanks for the reminding me to check previous threads !!

  7. #7
    Registered User
    Join Date
    Jun 2003
    Posts
    60
    Oi Speedy 5 !!!


    yeah ! its crude, simple.. but it works...

    your use of functions (or whatever you call it), mezmerizes me to the point that i have to browse my book over and over again..

    you got this fabulous:


    system("pause");


    Whew !!

    thanks dude !!

  8. #8
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Have you tried the example in the FAQ?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  9. #9
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    Unfortunately, the operation you are trying to accomplish will require your compiler to handle single character input, which is not standard.

    The compiler's I use (Borland and M$) have this capability using getch() as mentioned, but other compilers do not have this function. The ncurses.h
    may have something usable on Linux.

    Speedy5's post is close to how I'd do it too, except for not testing for too many chars typed.

    Oh, and instead of using the overhead of system("pause");, why not jus use getch();?
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  10. #10
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    Thats why I said it was crude.

    And its just habit using system-pause. I've always done it and the overhead is so dumb. Its at the end of the program! But yea, use this instead. Its more portable, faster, and uses less memory:
    Code:
    printf("\n\nPress any key to continue . . . ");
    _getch();
    return 0;

  11. #11
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    Originally posted by Speedy5
    Thats why I said it was crude.

    And its just habit using system-pause. I've always done it and the overhead is so dumb. Its at the end of the program! But yea, use this instead. Its more portable, faster, and uses less memory:
    Code:
    printf("\n\nPress any key to continue . . . ");
    _getch();
    return 0;
    Au contraire, it is less portable. See my previous post. Use:
    Code:
    printf("\n\nPress ENTER to continue . . . ");
    getchar();
    return 0;
    That is portable.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21