Сравнить две строки с игнорированием регистра
#include <strings.h>int strcasecmp( const char *str1,const char *str2 );
libc
Функция strcasecmp() сравнивает строки, адресуемые параметрами str1 и str2, игнорируя их регистр.
#include <stdio.h>#include <strings.h>#include <stdlib.h>void compare( const char *s1, const char *s2 ){int retval;retval = strcasecmp( s1, s2 );if ( retval > 0 ){printf( "%s > %s\n", s1, s2 );} elseif ( retval < 0 ){printf( "%s < %s\n", s1, s2 );} else {printf( "%s == %s\n", s1, s2 );}}int main( void ){char *str1 = "abcdefg";char *str2 = "HIJ";char *str3 = "Abc";char *str4 = "aBCDEfg";compare( str1, str2 );compare( str1, str3 );compare( str1, str4 );compare( str1, str1 );compare( str2, str2 );compare( str2, str3 );compare( str2, str4 );compare( str2, str1 );return (EXIT_SUCCESS);}
Код генерирует следующий вывод:
$ ./a.out abcdefg < HIJ abcdefg > Abc abcdefg == aBCDEfg abcdefg == abcdefg HIJ == HIJ HIJ > Abc HIJ > aBCDEfg HIJ > abcdefg
POSIX 1003.1 X/Open Systems Interfaces Extension
strcmp(), strcmpi(), strcoll(), stricmp(), strncasecmp(), strncmp(), strnicmp(), wcscmp(), wcscoll(), wcsncmp()
Предыдущий раздел: Описание API системной библиотеки