Some of the previous answers have suggested workarounds such as looping through the entire array and converting it to all uppercase, or all lowercase, before doing the search or compare.
#include <iostream>
#include <cctype>
usingnamespace std;
int strncmpi( char *str1, char *str2, int n )
{
for ( int i = 0; i < n; i++ )
{
char c1 = tolower( str1[i] ), c2 = tolower( str2[i] );
if ( c1 < c2 ) return -1; // includes str1 terminating, str2 not
if ( c1 > c2 ) return 1; // includes str2 terminating, str1 not
if ( c1 == '\0' ) return 0; // given the above, both must terminate here
}
return 0;
}
// Test ...
int main()
{
char s[] = "myGameEnd";
char s1[] = "gameend";
int n = 6; // change to what you want
cout << s << " " << s1 << " " << strncmpi( s, s1, n ) << '\n';
}
myGameEnd gameend 1
It produces 1 (not -1) because the first character m > g, irrespective of case.
Your original question asked for strncmpi, which is available in some computer languages and as an add-on in some implementations of c++ - but not in the standard. However, your subsequent replies suggest that (as @Chervil pointed out following your answer) you might be looking for one string inside another. That is a different problem. You need to be clear about what you actually require. Maybe you can give us some context?