Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef STRCASECMP_H
- #define STRCASECMP_H
- #include <cctype>
- #include <iostream>
- //definitions.h
- //#define strcasecmp _stricmp
- //#define strncasecmp _strnicmp
- int strcasecmp (const char *s1, const char *s2)
- {
- while (*s1 != 0 && *s2 != 0)
- {
- if (*s1 != *s2 && ::toupper (*s1) != ::toupper(*s2))
- {
- return -1;
- }
- s1++;
- s2++;
- }
- return (*s1 == 0 && *s2 == 0) ? 0 : -1;
- }
- int strncasecmp(const char *s1, const char *s2, int n)
- {
- if (n && s1 != s2)
- {
- do {
- int d = tolower(*s1) - tolower(*s2);
- if (d || *s1 == '\0' || *s2 == '\0') return d;
- s1++;
- s2++;
- } while (--n);
- }
- return 0;
- }
- #endif // STRCASECMP_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement