Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

String equality tester (See related posts)

If you want to test the equality of two strings and don't want the overhead of strcmp(), then this is the function for you.
_Bool strequals(char* a, char* b) {
 if (!a || !b) return 0;
 do {if (*a != *b) return 0; } while (*a++ && *b++);
 return 1;
}

Comments on this post

gciutac posts on Aug 03, 2007 at 08:09
What will happen in case of two different lenght strings like:
"mystring" and
"mystring2"? I thing it will return also true even the strings are not
tpicot posts on Aug 06, 2007 at 06:02
No.. it will work fine. However, "the overhead of strcmp" is dubious, I'd take a punt that this would be slower than the one provided by the library.

You need to create an account or log in to post comments to this site.


Click here to browse all 4860 code snippets

Related Posts