ustrncmp(3)

πŸ“¦ version 4.4.3.1, in fedora 43, fedora 44

πŸ’– ustrncmp β€” ok bestie, let's compare some strings (but like, only the first n of them) πŸ’–

So this is ustrncmp, a lil function from the Allegro game programming library, and she's here to compare up to n letters of two strings. No cap. πŸ¦‹


✨ SYNOPSIS ✨

#include <allegro.h>

int ustrncmp(const char *s1, const char *s2, int n);

🌸 DESCRIPTION 🌸

Okay so picture this: you got two strings, s1 and s2, and you're like "hmm, do these two match for the first little bit?" That's literally what this function does, bestie. It compares up to n characters of s1 and s2. Not the whole thing. Just n. The way that's so useful for checking prefixes, I'm obsessed. πŸ’…

Here's the iconic example from the original:

if (ustrncmp(prefix, long_string, ustrlen(prefix)) == 0) {
   /* long_string starts with prefix */
}

See what she did there? Compares prefix against long_string for exactly ustrlen(prefix) characters, and if it comes back 0, then long_string starts with prefix. Chef's kiss. πŸŽ€


⭐ RETURN VALUE ⭐

  • Returns zero if the substrings are equal πŸ‘‘
  • Returns a positive number if s1 comes after s2 in the ASCII collating sequence πŸ”₯
  • Otherwise (aka else), a negative number πŸ’œ

🌈 SEE ALSO 🌈


That's the whole vibe, bestie. Go forth and compare your prefixes responsibly. πŸ’–βœ¨πŸŽ€πŸ¦‹

Mwah! This has been Allegro, version 4.4.3, serving ustrncmp(3) realness. Periodt. πŸ’…πŸ‘‘

πŸ“¦ where this page comes from