change character while in scanf

This is a discussion on change character while in scanf within the C Programming forums, part of the General Programming Boards category; Hi You know how in some sites they cover the password with stars? well, I wanna do the same thing ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    14

    Question change character while in scanf

    Hi
    You know how in some sites they cover the password with stars?
    well, I wanna do the same thing in 'C', but instead of characters
    I wanna do it with only spaces.. For Example, if the person wants to put his/her name and they put Space in between
    (e.g. John Edward), but if they put space, it will skip the next scanf.. What I want instead is when they input a space ' ', it will be replaced with underscore '_' or a character that acts like a space.. Any Ideas on how to do that??
    Thanks in advance

  2. #2
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    Or put the input in a loop and read a single character at a time until CR is pressed. For this use
    1) getch() which will input a character but not output it
    2) Test the character and change it if necessary
    3) Add the character to your input array
    4) use putchar() to output the character to the screen
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. type casting?
    By greatonesv in forum C Programming
    Replies: 12
    Last Post: 10-22-2008, 08:21 PM
  2. Replies: 11
    Last Post: 10-07-2008, 06:19 PM
  3. scanf(), Parameter Passing, and Character Arrays
    By linguae in forum C Programming
    Replies: 2
    Last Post: 05-02-2005, 04:19 AM
  4. character occurrence program not working
    By Nutshell in forum C Programming
    Replies: 6
    Last Post: 01-21-2002, 09:31 PM
  5. Replies: 2
    Last Post: 09-04-2001, 02:12 PM

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