ustrstr(3alleg4)

πŸ’– ustrstr β€” bestie edition πŸ’–

okay so this is ustrstr from the Allegro manual, and if you're here it's because you need to find a string inside another string and you need it to be Unicode-friendly. welcome, you're in the right place, let's go ✨


✨ NAME ✨

ustrstr β€” finds the first occurrence of a string in another one. Allegro game programming library. that's literally the whole job. she's focused, she's employed, she ate πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <allegro.h>

char *ustrstr(const char *s1, const char *s2);

look at her. two const char * and a char * return. clean. minimal. iconic.


🌸 DESCRIPTION 🌸

so the way this works is β€” this function finds the first occurrence of string s2 in string s1. like, s2 is the little friend you're looking for and s1 is the big crowd she's hiding in, and ustrstr is gonna go find her πŸ”

example, since we love a demo:

char *p = ustrstr("hello world", "world");

and boom, p points at the "world" part. main character behaviour fr fr.

ngl this is the Allegro-flavoured cousin of the regular string search β€” it's the one you want in the Unicode-aware Allegro world. iykyk 🧚

πŸ’œ RETURN VALUE πŸ’œ

returns a pointer within s1, or NULL if s2 wasn't found. that's it. that's the deal.

so if she's there, you get a pointer into the original string (not a copy, not a new allocation β€” a pointer into s1, okay bestie, remember that). if she's not there? NULL. not found, no drama, just NULL πŸ’€ always check for it, i'm begging 🫢


πŸŽ€ SEE ALSO πŸŽ€

the whole unicode string girl squad, all in one place 🌈


and that's the page!! this was Allegro, version 4.4.3, and yeah she's old but she still slays πŸ‘‘ take care of your pointers, check for NULL, and go find your strings bestie πŸ’–βœ¨