ฟังก์ชัน strcoll() ใช้เพื่อเปรียบเทียบสองสตริงโดยใช้โลแคล - ลำดับการเรียงเฉพาะ
มันกลับมา -
- ศูนย์ เมื่อทั้งสองสตริงเหมือนกัน
- ค่ามากกว่าศูนย์เมื่อสตริงแรกมากกว่าค่าอื่น
- น้อยกว่าค่าศูนย์ เมื่อสตริงแรกน้อยกว่าค่าอื่น
นี่คือไวยากรณ์ของ strcoll() ในภาษา C
int strcoll(const char *first_string, const char *second_string);
นี่คือตัวอย่าง strcoll() ในภาษา C
ตัวอย่าง
#include <stdio.h>
#include <string.h>
int main () {
const char s1[] = "Helloworld";
const char s2[] = "Blank";
char *result;
result = strcoll(s1, s2);
if(result > 0)
printf("String s1 is greater than string s2");
else if(result < 0)
printf("String s1 is less than string s2");
else
printf(" Strings are not same");
return(0);
} ผลลัพธ์
String s1 is greater than string s2