ustrncmp(3)
π 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
s1comes afters2in 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
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms