F
Frederik Van Bogaert
Hi! I've taken my first steps into the world of c++ by trying to write a
text adventure game. Things are proceeding fine, but there's some code
in there that isn't very well coded. More specifically, I use the
following code:
...
string word [4];
size_t pos = action.find(" ");
word[0] = action.substr (0,pos);
if (pos < action.size() - 2)
{
word[1] = action.substr(pos + 1);
}
string word1 [2];
for (int i=1;i<3;i++)
{
pos = word.find(" ");
if (pos == string::npos) goto skippy;
word1[i-1] = word.substr (0,pos);
if (pos < word.size() - 2)
{
word[i+1] = word.substr(pos + 1);
}
word = word1[i-1];
}
skippy:
...
To convert a string called 'action' into the array word[4]. Is there a
way to do this more efficiently?
Thanks
text adventure game. Things are proceeding fine, but there's some code
in there that isn't very well coded. More specifically, I use the
following code:
...
string word [4];
size_t pos = action.find(" ");
word[0] = action.substr (0,pos);
if (pos < action.size() - 2)
{
word[1] = action.substr(pos + 1);
}
string word1 [2];
for (int i=1;i<3;i++)
{
pos = word.find(" ");
if (pos == string::npos) goto skippy;
word1[i-1] = word.substr (0,pos);
if (pos < word.size() - 2)
{
word[i+1] = word.substr(pos + 1);
}
word = word1[i-1];
}
skippy:
...
To convert a string called 'action' into the array word[4]. Is there a
way to do this more efficiently?
Thanks