DeAI Research
Source · man

strcmp(3) - Linux manual page

2008

cid 112aa16f83220a47615ad55f3b9b3bd3c1b3e25b9e105e5d4ff48acfae53130f · original · open access · via man

Title: strcmp(3) - Linux manual page
Authors: 
Venue: man
Year: 2008
Canonical: man:man3/strcmp.3
URL: https://man7.org/linux/man-pages/man3/strcmp.3.html
Collector: man
OA: true

ABSTRACT
strcmp(3) - Linux manual page man7.org Linux man-pages Linux/UNIX system programming training strcmp(3) — Linux manual page NAME | LIBRARY | SYNOPSIS | DESCRIPTION | RETURN VALUE | ATTRIBUTES | STANDARDS | HISTORY | CAVEATS | EXAMPLES | SEE ALSO | COLOPHON strcmp(3) Library Functions Manual strcmp(3) NAME top strcmp - strings compare LIBRARY top Standard C library (libc, -lc) SYNOPSIS top #include int strcmp(const char *s1, const char *s2); DESCRIPTION top The strcmp() function compares the two strings s1 and s2, as if by calling memcmp(3). It is equivalent to memcmp(s1, s2, MIN(strlen(s1),strlen(s2))+1) RETURN VALUE top See memcmp(3). ATTRIBUTES top For an explanation of the terms used in this section, see attributes(7). ┌──────────────────────────────────────┬───────────────┬─────────┐ │ Interface │ Attribute │ Value │ ├──────────────────────────────────────┼───────────────┼─────────┤ │ strcmp() │ Thread safety │ MT-Safe │ └──────────────────────────────────────┴───────────────┴─────────┘ STANDARDS top C11, POSIX.1-2008. HISTORY top POSIX.1-2001, C89, SVr4, 4.3BSD. CAVEATS top The locale is not taken into account (for a locale-aware comparison, see strcoll(3)). EXAMPLES top The program below can be used to demonstrate the operation of strcmp(). $ ./strcmp ABC ABC; and are equal $ ./strcmp ABC AB; # 'C' is ASCII 67; 'C' - '\0' = 67 is greater than (67) $ ./strcmp ABA ABZ; # 'A' is ASCII 65; 'Z' is ASCII 90 is less than (-25) $ ./strcmp ABJ ABC; is greater than (7) $ ./strcmp $'\201' A; # 0201 - 0101 = 0100 (or 64 decimal) is greater than (64) The last example uses bash(1)-specific syntax to produce a string containing an 8-bit ASCII code; the result demonstrates that the string comparison uses unsigned characters. Program source // strcmp.c // Licensed under GNU General Public License v2 or later. #include #include #include int main(int argc, char *argv[]) { int res; if (argc != 3) { fprintf(stderr, "Usage: %s \n", argv[0]); exit(EXIT_FAILURE); } res = strcmp(argv[1], argv[2]); if (res == 0) { printf(" and are equal"); printf("\n"); } else if (res is less than (%d)\n", res); } else { printf(" is greater than (%d)\n", res); } exit(EXIT_SUCCESS); } SEE ALSO top memcmp(3), strcasecmp(3), strcoll(3), streq(3), string(3), strverscmp(3), wcscmp(3) COLOPHON top This page is part of the man-pages (Linux kernel and C library user-space interface documentation) project. Information about the project can be found at ⟨https://www.kernel.org/doc/man-pages/⟩. If you have a bug report for this manual page, see ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩. This page was obtained from the tarball man-pages-6.19.tar.gz fetched from ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on 2026-09-09. If you discover any rendering problems in this HTML version of the page, or you believe there is a better or more up- to-date source for the page, or you have corrections or improvements to the information in this COLOPHON (which is not part of the original manual page), send a mail to man-pages@man7.org Linux man-pages 6.19 2026-08-10 strcmp(3) Pages that refer to this page: bash(1), pmlogrewrite(1), hsearch(3), qsort(3), scandir(3), selinux_file_context_cmp(3), strcasecmp(3), strcoll(3), string(3), strncmp(3), strverscmp(3), strxfrm(3), wcscmp(3), signal-safety(7) HTML rendering created 2026-09-09 by Michael Kerrisk, author of The Linux Programming Interface. For details of in-depth Linux/UNIX system programming training courses that I teach, look here. Hosting by jambit GmbH.