
strncasecmp 함수는 두 문자열을 비교할 때, 비교할 문자열의 길이를 지정할 수 있는 함수입니다.
strncasecmp 함수의 일반적인 사용 형식은 다음과 같습니다.
#hostingforum.kr
c
int strncasecmp(const char *s1, const char *s2, size_t n);
* `s1`과 `s2`는 비교할 문자열입니다.
* `n`은 비교할 문자열의 길이입니다.
예를 들어, "apple"과 "Apple"을 비교할 때, 5글자까지만 비교하는 방법은 다음과 같습니다.
#hostingforum.kr
c
#include
#include
int main() {
const char *str1 = "apple";
const char *str2 = "Apple";
int result = strncasecmp(str1, str2, 5);
if (result < 0) {
printf("%s는 %s보다 작습니다.n", str1, str2);
} else if (result > 0) {
printf("%s는 %s보다 큽니다.n", str1, str2);
} else {
printf("%s와 %s는 같습니다.n", str1, str2);
}
return 0;
}
이 예제에서, `strncasecmp` 함수는 "apple"과 "Apple"을 5글자까지만 비교합니다. 결과는 "apple"이 "Apple"보다 작습니다.
2025-07-26 03:21