strcmp(3) Library Functions Manual strcmp(3) strcmp, strncmp - (libc -lc) #include int strcmp(const char *s1, const char *s2); int strncmp(const char s1[], const char s2[], size_t n); strcmp() strcmp() s1 s2 memcmp(3). ( strcoll(3)). memcmp(s1, s2, MIN(strlen(s1),strlen(s2))+1) strncmp() strncmp() ( ) n s1 s2. memcmp(s1, s2, MIN(MIN(strnlen(s1,n),strnlen(s2,n))+1, n)) strcmp() strncmp() s1 ( n ) s2 . attributes(7). +------------+------------------------------------+--------------------+ || | | +------------+------------------------------------+--------------------+ |strcmp(), | | MT-Safe | |strncmp() | | | +------------+------------------------------------+--------------------+ POSIX.1 : ( unsigned char) . glibc s2 s1. ( 0.) C11, POSIX.1-2008. POSIX.1-2001 C89 SVr4 4.3BSD. strcmp() ( ) strncmp() ( ). strcmp(): $ ./string_comp ABC ABC; $ ./string_comp ABC AB; # 'C' ASCII 67; 'C' - '\0' = 67 (67) $ ./string_comp ABA ABZ; # 'A' ASCII 65; 'Z' ASCII 90 (-25) $ ./string_comp ABJ ABC; (7) $ ./string_comp $'\201' A; # 0201 - 0101 = 0100 ( 64 ) (64) bash(1) ASCII 8- . strncmp(): $ ./string_comp ABC AB 3; (67) $ ./string_comp ABC AB 2; 2 /* string_comp.c 2 . */ #include #include #include int main(int argc, char *argv[]) { int res; if (argc < 3) { fprintf(stderr, ": %s []\n", argv[0]); exit(EXIT_FAILURE); } if (argc == 3) res = strcmp(argv[1], argv[2]); else res = strncmp(argv[1], argv[2], atoi(argv[3])); if (res == 0) { printf(" "); if (argc > 3) printf(" %d \n", atoi(argv[3])); printf("\n"); } else if (res < 0) { printf(" (%d)\n", res); } else { printf(" (%d)\n", res); } exit(EXIT_SUCCESS); } memcmp(3), strcasecmp(3), strcoll(3), streq(3), string(3), strncasecmp(3), strverscmp(3), wcscmp(3), wcsncmp(3), ascii(7) 3 . . : . 6.18 16 2026 strcmp(3)