inputs and spaces... help please!

This is a discussion on inputs and spaces... help please! within the Game Programming forums, part of the General Programming Boards category; I am trying to make a text based game and was wondering 2 things: 1) what type of input i ...

  1. #1
    Unregistered
    Guest

    inputs and spaces... help please!

    I am trying to make a text based game and was wondering 2 things:
    1) what type of input i sould use to allow the user to input spaces
    2) How i could break apart that input BY the spaces

    For instance:
    The user inputs "kill dragon"

    I want the program to do this:
    Char input[50];
    char kill_destination[10];

    cin >> input //not unsing cin, because that does not work

    if(strcmp(input,"kill ____") == 0)
    {
    kill_destination = input - "kill";
    }


    and so on.... HOW DO I DO THIS???

  2. #2
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    To see if a string contains a word, you can use strstr(). If you want to get input, you can use fgets() in stdio.h. If you want to get rid of the first part of the word. You can do this:
    Code:
    Input[50] = "kill dragon";
    char* Object = &Input[5];
    Now the string that Object points to is "dragon". Or you could set the first 4 char to a space and then use strtrim. To get rid of the spaces, thus leaving you with "dragon".

    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf with two inputs acting funny
    By yougene in forum C Programming
    Replies: 2
    Last Post: 08-19-2007, 04:17 PM
  2. Remove Spaces?
    By 98dodgeneondohc in forum C Programming
    Replies: 15
    Last Post: 04-21-2005, 10:16 AM
  3. program is checking for ent when user inputs out?
    By Blizzarddog in forum C++ Programming
    Replies: 1
    Last Post: 04-07-2003, 01:16 PM
  4. Printing Spaces between 5 digit integer
    By Dan529 in forum C Programming
    Replies: 3
    Last Post: 02-08-2003, 03:15 PM
  5. Spaces in Character Arrays
    By ADLOTS in forum C++ Programming
    Replies: 3
    Last Post: 11-25-2002, 03:24 AM

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