Thread: Password, color

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    11

    Question Password, color

    Hi there,

    I having a school project on c programming. There is some part i don't how to do. Like how to put color to my text. And when like

    printf("Enter your password: ");
    scanf("%s",&passsword);

    Display:
    Enter your password: 1234

    can any on teach mi how to do this:

    Display:
    Enter your password: ******

    but it will display the password that i would like to be scan instead of the hidding it.

    Thank

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    For the password part, try the FAQ.

    For the color part, search the boards.
    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 Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    for getting string for an stream, use fgets().

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by Vber
    for getting string for an stream, use fgets().
    But they want unbuffered input, so standard functions won't do the job I'm afraid. They'll need getch() or an equivalent of some sort (as per the FAQ already mentioned).
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    Hammer I meant, not about the **** and yes about the
    scanf("%s",&password);
    this is unbuffered too?

    Always when I write scanf("%s",&myStr); here, people always tell's me to change to fgets... wierd.
    Last edited by Vber; 03-16-2003 at 04:39 PM.

  6. #6
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >scanf("%s",&password);
    >this is unbuffered too?

    That's buffered. Scanf (and variations of it) store any keypresses into a buffer, and when the enter key is pressed, they then deal with the buffer.
    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

  7. #7
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    Ok, so Hammer tought that I'm talking about the **** input, that ofcourse, it's not with fgets, he'll need getch() or getchar() or whatever, I was talking about scanf("%s",&password);

    That's it

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    I see, we're getting a little mix up in our thoughts

    All standard input functions use buffered IO, fgets(), scanf(), getchar() etc etc.

    With regards to this:
    >>scanf("%s",&password)
    I would suggest that maybe password is already a char array, and therefore the code would look more like this:
    >>char password[100];
    >>scanf("%s",password);
    Note the & is not present as password is already a pointer being an array.

    But hey, I could be wrong, I've only got one line of code to go by..

    [edit]
    (I'm not promoting scanf(), btw, merely correcting the code in this thread. Check the FAQ for better ways to get strings from the user, if you don't know them already )
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #9
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    Well hammer I have no idea
    Hmm, always when I ask the best way to get a string from a stream people tell me to use fgets()

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Critique my lighting model.
    By psychopath in forum Game Programming
    Replies: 4
    Last Post: 08-12-2006, 06:23 PM
  2. [Q]Hide Password
    By Yuri in forum C++ Programming
    Replies: 14
    Last Post: 03-02-2006, 03:42 AM
  3. written command line password generator
    By lepricaun in forum C Programming
    Replies: 15
    Last Post: 08-17-2004, 08:42 PM
  4. Just one Question?
    By Irish-Slasher in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 10:19 AM
  5. password
    By hammers6 in forum C Programming
    Replies: 1
    Last Post: 10-10-2001, 12:14 AM