No, this is not a question! I'm just informing everyone I wrote a pretty good string comparison function which I think is a bit more powerful than strcmp(). For instance, strcmp() doesn't return false if the second string has spaces where the first doesn't. I've fixed this. Here's the code, it's pretty basic. It returns true if string 2 is the same as string 1, and false if it is different:
Code:
bool StrComp(char * str1, char * str2)
{
// loops through and checks, char by char, if equal
int i=0;
bool fail=false;
for( ;; )
{
// quit if str1[i] != str2[i]
if (str1[i] != str2[i])
{
fail = true;
break;
}
// this will even fail if str1[i] is a space and str2[i] isn't, unlike strcmp()
if (str1[i] == ' ' && str2[i] != ' ')
{
fail = true;
break;
}
// quit if reach end of string
if (str1[i] == '\0')
{
// return false if only one of the strings is done
if (str2[i] == '\0')
break;
else
{
fail = true;
break;
}
}
i++;
}
// fail
if (fail)
return false;
// dont fail
else
return true;
}
Just wanted to share that with everyone. I've found a little useful. I've got this thing with using pre-made functions. If I can, I always like to things my own way. Like with this: I'd much rather use something I personally created than something that the compiler includes. It makes me feel good that I can do something just as good as theirs. I'm wierd that way Anyways, hope you like it.
Brendan