STRLTRIM(3pub)

πŸ’– STRLTRIM(3pub) πŸ’–

okay bestie, so this is a page from the C Programmer's Manual (the publib one, you know the vibes), and it's all about strltrim β€” the little function that yeets whitespace off the front of your string. she's simple, she's reliable, she's lowkey iconic. let's get into it 🫢


✨ NAME ✨

strltrim β€” remove leading whitespace from a string

like... that's her whole job. that's the assignment. and she ate. πŸ’…


🌸 SYNOPSIS 🌸

#include <publib.h>
char *strltrim(char *s);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea: strltrim removes all leading whitespace characters from the beginning of a string. how does she do it? not me asking the real questions β€” she does it by moving everything starting from the first non-whitespace character all the way to the beginning of the string. like, packing up and relocating to the front. main character energy fr fr. πŸ‘‘

and what counts as "whitespace"? literally everything for which isspace(3) returns true. that's the vibe check. if isspace(3) says yes, it's whitespace, and it's getting trimmed. periodt.


πŸ’œ RETURN VALUE πŸ’œ

strltrim returns its argument. yes, the same pointer you handed her. she gives it right back. no cap. πŸŽ€


⭐ EXAMPLE ⭐

okay so say you wanna remove all the indentation from all the lines in a program β€” here's how you'd do it:

#include <publib.h>

int main(void) {
     char line[512];

     while (fgets(line, sizeof(line), stdio) != NULL) {
          strltrim(line);
          printf("%s", line);
     }
     return 0;
}

she reads a line, trims the front, prints it. over and over. it's giving dedicated. πŸ”₯


🌈 SEE ALSO 🌈

(the whole trim squad 🫢 β€” strrtrim does the back end, strtrim does both, and isspace is the one deciding what even counts.)


πŸ‘‘ AUTHOR πŸ‘‘

Lars Wirzenius (lars.wirzenius@helsinki.fi) β€” thank you king, we appreciate you πŸ’–


and that's the whole page bestie! no missing details, no skipped sections, every single thing preserved. iykyk 😭✨

this iconic lil manual page is brought to you by Publib, dated as part of the C Programmer's Manual, filed under STRLTRIM(3pub). mwah πŸ’‹ stay trimmed, stay slaying πŸ¦‹πŸŒΈπŸ’…

πŸ“¦ where this page comes from