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 by s1 is greater than the possibly null-terminated array pointed to by s2
  • equal to 0 โ€” if those two arrays are equal
  • less than 0 โ€” if the array pointed to by s1 is less than the array pointed to by s2

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>


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