SDL_strcmp(3)

πŸ’– SDL_strcmp(3) πŸ’–

the SDL3 functions girlies present… a whole function for comparing two null-terminated UTF-8 strings, and honestly? iconic. welcome to the SDL_strcmp page, bestie 🫢


✨ NAME ✨

SDL_strcmp β€” compare two null-terminated UTF-8 strings. that's it, that's the job πŸ’…


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_stdinc.h>

int SDL_strcmp(const char *str1, const char *str2);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the tea β˜• β€” because of the whole nature of UTF-8 encoding, this function just works with Unicode strings. like, no extra effort needed. why? because effectively all it does is compare bytes until it hits a null-terminating character. that's the whole vibe. byte by byte until the \0 shows up, periodt.

and also, again because UTF-8 is just Like That, you can totally pair this with SDL_qsort() to put your strings in (roughly) alphabetical order. note the roughly β€” it's giving "good enough", not "perfectly sorted by your language's collation rules". it ate but it's not doing the most πŸ’€


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • str1 β€” the first string to compare. NULL is not permitted! like, do NOT. πŸ™ˆ
  • str2 β€” the second string to compare. NULL is not permitted! same energy, same warning. 🚫

⭐ RETURN VALUE ⭐

  • returns less than zero if str1 is "less than" str2 πŸ“‰
  • returns greater than zero if str1 is "greater than" str2 πŸ“ˆ
  • returns zero if the strings match exactly ✨ (a perfect match, main character energy πŸ‘‘)

🧚 THREAD SAFETY 🧚

it is safe to call this function from any thread. no cap. go wild, queen 🌈


πŸ’œ AVAILABILITY πŸ’œ

this function is available since SDL 3.2.0. old enough to be trusted, young enough to be cute πŸ“


lowkey reminder: no NULLs allowed in either spot. fr fr. protect your pointers bestie 😭

and that's the whole page, you understood it perfectly, slay πŸ’…βœ¨

signing off with love from the Simple Directmedia Layer babes β€” this is SDL 3.4.18, mwah πŸŽ€πŸ’–πŸ¦‹

πŸ“¦ where this page comes from