STRCMP(3P)
β¨ PROLOG β¨
ok so bestie, quick heads up before we dive in π this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so like, consult the corresponding Linux manual page for the tea on Linux behavior), or the interface may not even be implemented on Linux at all. not me warning you before you get attached π
πΈ NAME πΈ
strcmp β compare two strings π
(yes that's it, that's the whole job)
π SYNOPSIS π
#include <string.h>
int strcmp(const char *s1, const char *s2);
π¦ DESCRIPTION π¦
So the functionality described on this reference page? It's aligned with the ISO C standard. If there's any conflict between what's written here and the ISO C standard, that's unintentional bestie, no cap. This volume of POSIX.1β2017 defers to the ISO C standard. periodt.
The strcmp() function shall compare the string pointed to by s1 to the string pointed to by s2.
And here's the part where it gets β¨specificβ¨ β the sign of a non-zero return value shall be determined by the sign of the difference between the values of the first pair of bytes (both interpreted as type unsigned char) that differ in the strings being compared. iykyk π₯
π RETURN VALUE π
Upon completion, strcmp() shall return an integer greater than, equal to, or less than 0, if the string pointed to by s1 is greater than, equal to, or less than the string pointed to by s2, respectively. it's giving "one number, three moods" π
π ERRORS π
No errors are defined. literally none. she simply does not miss π«Ά
The following sections are informative.
π EXAMPLES π
π Checking a Password Entry
ok so this example compares the info read from standard input to the value of the name of the user entry. If the strcmp() function returns 0 (indicating a match π), a further check will be made to see if the user entered the proper old password. The crypt() function shall encrypt the old password entered by the user, using the value of the encrypted password in the passwd structure as the salt. If this value matches the value of the encrypted passwd in the structure, the entered password oldpasswd is the correct user's password. Finally, the program encrypts the new password so that it can store the information in the passwd structure. main character energy fr fr π
#include <string.h>
#include <unistd.h>
#include <stdio.h>
...
int valid_change;
struct passwd *p;
char user[100];
char oldpasswd[100];
char newpasswd[100];
char savepasswd[100];
...
if (strcmp(p->pw_name, user) == 0) {
if (strcmp(p->pw_passwd, crypt(oldpasswd, p->pw_passwd)) == 0) {
strcpy(savepasswd, crypt(newpasswd, user));
p->pw_passwd = savepasswd;
valid_change = 1;
}
else {
fprintf(stderr, "Old password is not valid\n");
}
}
...
π§ APPLICATION USAGE π§
None. nothing to add, she said what she said π
π RATIONALE π
None. the reasoning is simply immaculate and needs no defense β¨
β FUTURE DIRECTIONS β
None. she's perfect and she's staying exactly like this, no notes π
πΈ SEE ALSO πΈ
strncmp()β the sibling, the one who counts π«Ά
The Base Definitions volume of POSIX.1β2017, <string.h> β go read the header bestie, it's got the lore π
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page babes π this one came to you from IEEE/The Open Group, 2017 β the STRCMP(3P) era, iconic, no cap. go compare some strings responsibly πβ¨
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms