
strcoll 함수는 locale에 따라 다르며, locale을 설정하는 방법은 다음과 같습니다.
1. locale을 설정하기 전에, locale을 확인하는 방법은 setlocale 함수를 사용합니다.
#hostingforum.kr
c
#include
#include
int main() {
char *locale = setlocale(LC_ALL, NULL);
if (locale == NULL) {
printf("locale 설정 실패n");
return 1;
}
printf("현재 locale: %sn", locale);
return 0;
}
2. locale을 설정하는 방법은 setlocale 함수를 사용합니다.
#hostingforum.kr
c
#include
#include
int main() {
char *locale = setlocale(LC_ALL, "ko_KR.UTF-8");
if (locale == NULL) {
printf("locale 설정 실패n");
return 1;
}
printf("현재 locale: %sn", locale);
return 0;
}
3. strcoll 함수는 locale의 설정에 따라서 대소문자 구분을 하지 않는 경우도 있습니다. 예를 들어, ko_KR locale에서는 대소문자를 구분하지 않습니다.
#hostingforum.kr
c
#include
#include
#include
int main() {
setlocale(LC_ALL, "ko_KR.UTF-8");
char str1[] = "Hello";
char str2[] = "hello";
int result = strcoll(str1, str2);
if (result == 0) {
printf("str1과 str2는 동일합니다.n");
} else {
printf("str1과 str2는 다릅니다.n");
}
return 0;
}
이 코드를 실행하면, "str1과 str2는 동일합니다."가 출력됩니다.
2025-03-28 11:49