Thread: User Commands

  1. #1
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719

    User Commands

    Hi, I wanted to make a simple program, well.....a game actually. Where you can type key commands in such as 'exit' , 'forward', 'drop', etc. So when i am coding this would i have to do different spellings of the same word, ex. 'exit' 'EXIT' 'Exit'. If the user types in 'ExiT' , the program wouldnt recognize this. So how can i account for user errors without having to do all these combos? or is their no other way?

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    As input comes in, convert everything to CAPS. There are a variety of methods of doing this. You could use toupper(char) from <ctype> in a loop, though there is probably a better method for strings in the STL.

  3. #3
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    I see.......i guess that could work. Let me try it..... Thanks

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Hmmm.. I was about to post the similar answer with tolower(), but I guess caps works, too.

    Basically create a fuction that accepts your string, then converts every element in the string array to lower(or upper)case.

    Then you can do something similar to:
    Code:
    } while (strConvert(userInput) == "EXIT");
    Last edited by SlyMaelstrom; 11-05-2005 at 07:58 PM.
    Sent from my iPadŽ

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Add/Delete Remotely a user
    By Scarvenger in forum Windows Programming
    Replies: 5
    Last Post: 03-24-2008, 08:36 AM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. Replies: 4
    Last Post: 04-21-2004, 04:18 PM
  4. ~ User Input script help~
    By indy in forum C Programming
    Replies: 4
    Last Post: 12-02-2003, 06:01 AM
  5. Stopping a user from typeing.
    By knave in forum C++ Programming
    Replies: 4
    Last Post: 09-10-2001, 12:21 PM