Comparing two strings

hello all i am writing a text mud in ansi-c and am having some trouble comparing
strings of text when spaces are involved.

here is my function to compare two strings:

1
2
3
4
5
6
7
8
9
10
int sameto(const char *shorts,const char *longs)
{
     while(*shorts!='\0')
     {
         if(tolower(*shorts)!=tolower(*longs)) return(0);
         shorts++;
         longs++;
     }
     return(1);
}


this works for single worded names like so:

1
2
3
4
5
6
7
8
9
10
11
const char *monster = "dragon";
const char *target = "dra"

if(sameto(monster,target)) 
{
   printf("\nAttacking the %s\r",monster);
}
else
{
   printf("\nUnable to attack the target!\r");
}


now what if the monster was "red dragon"
the sameto function would stop at "red" and b/c of the space
would not process the 'dragon' part.

so in the game if i type "attack dragon" and the monsters
name was "red dragon" i want it to process.

can anyone lend a hand?

thanks you.
Why would it stop at the space? You're looping until you read the terminated null character.
Topic archived. No new replies allowed.