Thread: Seeking Help x.x

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    8

    Seeking Help x.x

    Hellos, I've look all over the website and google and I still can't find anything relating to what I need :x Well I'm just learning C++ and I'm playing around with the cmd/dos window or whatever, and I've learned quite a bit. (or I think so :P) What I'm trying to do is get my input to be like formatted. Like say when I run my program it asks for a number, and let's say I enter 1112223333, is there anyway I can get it to automatically enter dashes as I type so it comes out like 111-222-3333? Or is it impossible?

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Sure it's possible, but it's also probably non-standard. Check out the faq on "How can I get input without having the user hit [Enter]?" for a few possible starting points.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    8
    wow how did I miss that one o.o must be too late in the night

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    8
    Thanks alot, I've got it working just how I want it, except for backspace. I know HOW to do it, you just backup a spot, then print a blank space over it, then backup agian. The problem is I'm having a hard time trying to visualize the flow of the program and how I would incorperate the user hitting backspace. Here's what I have so far:
    Code:
                do {
                    //check our location in the string and decide if to put a dash or not
                    if (i == 1 && ch != 84 || i == 5 && ch != 84) {
                        cout << "-";
                        userInput[i] = (char)45;
                    } else {
                        //get user input
                        ch = getch();
                        ch = toupper(ch);
                        
                        //only allow 0-9 and "T" as input
                        if (ch > 47 && ch < 58 || ch == 84) {
                            userInput[i] = (char)ch;                        
                            cout << (char)ch;
                        }
                    }
                    
                    //string iteration
                    i++;                               
                } while(ch != 13);
    Any advice is appreciated

  5. #5
    Registered User Kurisu's Avatar
    Join Date
    Feb 2006
    Posts
    62
    I would place your backspace routine after you get a char.
    Code:
    ch = getch();  // After this line.
    
    if(ch == BACKSPACE) // BACKSPACE is just pseudocode.
    {
    // Put backspace code here, which by your wording I'm assuming you know...
    // Probably something like [for starters]:
     i--;
    userInput[i] = ' ';
    }
    else
    {
      //only allow 0-9 and "T" as input
      if (ch > 47 && ch < 58 || ch == 84) {
          userInput[i] = (char)ch;                        
          cout << (char)ch;
      }



    Xeno....
    ...
    ...
    ...
    ..
    ..
    .
    .
    oasis?
    Last edited by Kurisu; 02-08-2006 at 12:37 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Filestream Not Seeking to the Beginning
    By pobri19 in forum C++ Programming
    Replies: 2
    Last Post: 04-11-2009, 03:59 AM
  2. Aeres seeking interested hoobyists!
    By Akkernight in forum Projects and Job Recruitment
    Replies: 13
    Last Post: 03-19-2009, 11:50 AM
  3. Seeking Head Coder for MUD Partnership
    By Draconar in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 06-25-2006, 04:05 PM