Hi, I have been working on a little text based interactive fiction game for a decent amount of time, but I just can't seem to figure out how I can cut up strings so that my program can understand simple commands. Is there a simple way to do this?
For instance, I want to be able to give a string to a function (a class might work better) like "get apple" so that my program can figure out that I want to use a "get" command on a "apple" item(if found). It doesn't have to be very complicated, I'm probably going to have the command only accept at most 3 words.
I've tried making a for loop so that it tries to find the first space in the string, then copy all the characters up to that point, but it just doesn't seem to be working at all. Plus it only captures the first word, so the end result won't help much in the first place.
If you want to see it however, here it is, I honestly want to just start from scratch again though.
string getFirstWord(string text)
{
bool firstWordFound = false;
string firstWord = "";
for(int i = 0; i <= text.length() && firstWordFound == false; i++)
{
if (text[i] = ' ')
{
firstWordFound = true;
for (int j = 0; j <= i; j++)
{
firstWord += text[j];
}
}
}
return firstWord;
}