inputs and spaces... help please! [Archive] - C Board

PDA

View Full Version : inputs and spaces... help please!


Unregistered
06-22-2002, 10:13 AM
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???

sean345
06-22-2002, 12:48 PM
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:

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