User Commands

This is a discussion on User Commands within the C++ Programming forums, part of the General Programming Boards category; Hi, I wanted to make a simple program, well.....a game actually. Where you can type key commands in such as ...

  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
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    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,069
    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 06: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, 10: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, 05:01 AM
  5. Stopping a user from typeing.
    By knave in forum C++ Programming
    Replies: 4
    Last Post: 09-10-2001, 12:21 PM

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