STRNCMP(3POSIX)
๐ strncmp(3POSIX) โ POSIX Programmer's Manual ๐
okay bestie, welcome to the POSIX Programmer's Manual page for strncmp โ it's the "compare part of two strings" girlie and she is so useful, fr fr. Grab a snack, we're doing this. ๐
๐ธ PROLOG ๐ธ
This manual page is part of the POSIX Programmer's Manual. Heads up though:
The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.
Not me warning you twice about portability. It's giving responsible bestie energy. ๐
โจ NAME โจ
strncmp โ compare part of two strings
That's it. That's the whole vibe. Comparing a little bit of two strings. ๐
๐ฆ SYNOPSIS ๐ฆ
#include <string.h>
int strncmp(const char *s1, const char *s2, size_t n);
Three args, one int back. Iconic. ๐
๐ DESCRIPTION ๐
Okay so first thing first: the functionality described on this reference page is aligned with the ISO C standard. Any conflict between the requirements described here and the ISO C standard is unintentional. This volume of POSIX.1โ2017 defers to the ISO C standard.
Now the actual tea: strncmp() shall compare not more than n bytes โ and btw, bytes that follow a NUL character are not compared โ from the array pointed to by s1 to the array pointed to by s2.
And how does it decide who's bigger? The sign of a non-zero return value is 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.
So like, it walks along, finds the first spot where they disagree, and that's the moment. main character byte. ๐
๐ฅ RETURN VALUE ๐ฅ
Upon successful completion, strncmp() shall return an integer that is:
- greater than
0โ if the possibly null-terminated array pointed to bys1is greater than the possibly null-terminated array pointed to bys2 - equal to
0โ if those two arrays are equal - less than
0โ if the array pointed to bys1is less than the array pointed to bys2
respectively. respectively, she said. ๐
๐ ERRORS ๐
No errors are defined.
The following sections are informative.
Literally nothing goes wrong here. We love a low-drama function. ๐
๐ EXAMPLES ๐
None.
(she's not gonna hold your hand, bestie, go write your own) ๐ซถ
โญ APPLICATION USAGE โญ
None.
๐ง RATIONALE ๐ง
None.
๐ฎ FUTURE DIRECTIONS ๐ฎ
None.
๐ SEE ALSO ๐
strcmp()
And also: The Base Definitions volume of POSIX.1โ2017, <string.h>
๐ 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 .
IEEE/The Open Group โ 2017 โ STRNCMP(3POSIX) ๐
โจ
and that's the whole page bestie, you ate, go compare some strings (but only the first n bytes, periodt ๐๐ฆ)
๐ฆ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 ยท Other
- debian trixie: manpages-posix-dev 2017a-2 ยท Other
- ubuntu jammy: manpages-posix-dev 2017a-2 ยท Other
- ubuntu noble: manpages-posix-dev 2017a-2 ยท Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 ยท Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 ยท Other
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms