in regards to games i am trying to find the best way to search a string for a shorthand match on a target.
example:
say you are in a room fighting a 'black dragon'
i want you to be able to use any characters from left to right
like:
attack b
attack bla
attack dra
attack dragon
any of those i want to work.
here is what i have been using on other programs:
this works fine as long as there are no spaces in the name.
so if the monster is "dragon" any character match from the d to the n it will take, ie: "attack dra"
however when it gets trickier like "black dragon"
anything within the name black it will take but the space stops it from matching because of the
any ideas?
example:
say you are in a room fighting a 'black dragon'
i want you to be able to use any characters from left to right
like:
attack b
attack bla
attack dra
attack dragon
any of those i want to work.
here is what i have been using on other programs:
bool sameto(const char *shorts,const char *longs)
/* compare short string to long string */
{
while(*shorts != '\0')
{
if(tolower(*shorts) != tolower(*longs))
{
return(false);
}
shorts++;
longs++;
}
return(true);
}
this works fine as long as there are no spaces in the name.
so if the monster is "dragon" any character match from the d to the n it will take, ie: "attack dra"
however when it gets trickier like "black dragon"
anything within the name black it will take but the space stops it from matching because of the
while(*shorts != '\0')
any ideas?