C strcasecmp() 대소문자 무시하고 문자열 비교 함수
C언어 문자열 비교 함수 strcasecmp()는 대소문자를 무시하고 2개의 문자열을 비교합니다.
- 헤더: string.h
- 형태: int * strcasecmp( const char *s1, const char *s2);
- 인수: char *s1 비교할 대상 문자열
char *s2 비교할 문자열 - 반환: 0 == 결과 값이면 s1 = s2
0 < 결과 값이면 s1 > s2
0 > 결과 값이면 s1 < s2
C언어 strcasecmp() 함수 예제
#include <stdio.h>
#include <string.h>
int main( void)
{
char str_apple[] = "apple";
char str_apple2[] = "Apple";
char str_apple3[] = " Apple";
char str_appleII[]= "AppleII";
printf( "%s with %s = %d\n", str_apple,str_apple ,strcasecmp( str_apple, str_apple ));
printf( "%s with %s = %d\n", str_apple,str_apple2 ,strcasecmp( str_apple, str_apple2 ));
printf( "%s with %s = %d\n", str_apple,str_apple3 ,strcasecmp( str_apple, str_apple3 ));
printf( "%s with %s = %d\n", str_apple,str_appleII,strcasecmp( str_apple, str_appleII));
return 0;
}
C언어 strcasecmp() 예제 실행 결과
]$ ./a.out
apple with apple = 0
apple with Apple = 0
apple with Apple = 65
apple with AppleII = -105
]$
'컴퓨터 > 프로그래밍' 카테고리의 다른 글
C언어 strncasecmp 함수 대소문자 무시하고 지정한 길이만큼 문자열 비교 (0) | 2020.03.10 |
---|---|
C언어 tolower 함수 대문자를 소문자로 변환 (2) | 2020.03.10 |
C언어 toupper 함수 소문자를 대문자로 변환 (0) | 2020.03.10 |