'\" t .\" Copyright 1993, David Metcalfe .\" Copyright 2020, Michael Kerrisk .\" Copyright, the authors of the Linux man-pages project .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .TH strcmp 3 2026-08-10 "Linux man-pages 6.19" .SH NAME strcmp \- strings compare .SH LIBRARY Standard C library .RI ( libc ,\~ \-lc ) .SH SYNOPSIS .nf .B #include .P .BI "int strcmp(const char *" s1 ", const char *" s2 ); .fi .SH DESCRIPTION The .BR strcmp () function compares the two strings .I s1 and .IR s2 , as if by calling .BR memcmp (3). .P It is equivalent to .P .in +4n .EX memcmp(s1, s2, MIN(strlen(s1),strlen(s2))+1) .EE .in .SH RETURN VALUE See .BR memcmp (3). .SH ATTRIBUTES For an explanation of the terms used in this section, see .BR attributes (7). .TS allbox; lbx lb lb l l l. Interface Attribute Value T{ .na .nh .BR strcmp () T} Thread safety MT-Safe .TE .SH STANDARDS C11, POSIX.1-2008. .SH HISTORY POSIX.1-2001, C89, SVr4, 4.3BSD. .SH CAVEATS The locale is not taken into account (for a locale-aware comparison, see .BR strcoll (3)). .SH EXAMPLES The program below can be used to demonstrate the operation of .BR strcmp (). .P .in +4n .EX .RB $ " ./strcmp ABC ABC" ; and are equal .RB $ " ./strcmp ABC AB" "; # \[aq]C\[aq] is ASCII 67; \[aq]C\[aq] \- \[aq]\[rs]0\[aq] = 67" is greater than (67) .RB $ " ./strcmp ABA ABZ" "; # \[aq]A\[aq] is ASCII 65; \[aq]Z\[aq] is ASCII 90" is less than (\-25) .RB $ " ./strcmp ABJ ABC" ; is greater than (7) .RB $ " ./strcmp $\[aq]\[rs]201\[aq] A" "; # 0201 \- 0101 = 0100 (or 64 decimal)" is greater than (64) .EE .in .P The last example uses .BR bash (1)-specific syntax to produce a string containing an 8-bit ASCII code; the result demonstrates that the string comparison uses unsigned characters. .SS Program source \& .\" SRC BEGIN (strcmp.c) .EX // 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 \[rs]n", argv[0]); exit(EXIT_FAILURE); } \& res = strcmp(argv[1], argv[2]); \& if (res == 0) { printf(" and are equal"); printf("\[rs]n"); } else if (res < 0) { printf(" is less than (%d)\[rs]n", res); } else { printf(" is greater than (%d)\[rs]n", res); } \& exit(EXIT_SUCCESS); } .EE .\" SRC END .SH SEE ALSO .BR memcmp (3), .BR strcasecmp (3), .BR strcoll (3), .BR streq (3), .BR string (3), .BR strverscmp (3), .BR wcscmp (3)