Tuesday, January 31, 2012

Ignoring Case when Comparing Strings

strcmpi() is the right function to compare strings while ignoring their cases (upper case or lower case).

Instead of looping an entire string just to convert each character to upper or lower case using toupper() or tolower(), we simply use strcmpi().


Sample Program:
Output:

Note: strcmpi() accepts 2 parameters, both are of type char[] that is why we called the function c_str() to convert s1 and s2 from string to char[].

No comments:

Post a Comment