STRTRIM(3pub)
π STRTRIM(3pub) β the C Programmer's Manual, but make it cute π
okay bestie, gather round, because today we're talking about strtrim from the publib gang. this is a page from the C Programmer's Manual and honestly? it's giving "small function, huge slay." π
β¨ NAME β¨
strtrim β remove leading and trailing whitespace π§Ήβ¨
β¨ SYNOPSIS β¨
#include <publib.h>
char *strtrim(char *s);
β¨ DESCRIPTION β¨
so here's the vibe: strtrim removes all whitespace characters from the beginning and the end of a string. that's it, that's the whole job, and it does it flawlessly. π
and what counts as "whitespace" you ask? literally everything for which isspace(3) returns true. so whatever isspace(3) says is whitespace, strtrim says is whitespace. they're besties, they agree on everything. π«Ά
β¨ RETURN VALUE β¨
strtrim returns its argument. yes, its own argument. it hands you back the very same pointer you gave it β lowkey iconic behaviour, no notes. π
β¨ EXAMPLE β¨
say you want to strip the whitespace off the front and back of every single line. you might do the following:
#include <publib.h>
int main(void) {
char line[512];
while (fgets(line, sizeof(line), stdio) != NULL) {
strtrim(line);
printf("%s", line);
}
return 0;
}
copy that, paste that, watch your lines get β¨cleanedβ¨. the way that strtrim(line) just casually fixes the whole line before you print it? main character energy fr fr. π
β¨ SEE ALSO β¨
the whole friend group, love that for them πΈ
β¨ AUTHOR β¨
Lars Wirzenius (lars.wirzenius@helsinki.fi) β the author, the legend, the moment. π
ngl bestie, this one's a short read, but it ate and left no crumbs. no cap. π
and that's a wrap! this lil page came to you from Publib, the C Programmer's Manual, and it's the STRTRIM(3pub) era of your life now. go forth and trim those strings, queen. π
β¨π¦π
π¦ where this page comes from
- debian bookworm: publib-dev 0.40-3+b1 Β· BSD-2-Clause
- debian trixie: publib-dev 0.40-4 Β· BSD-2-Clause
- ubuntu jammy: publib-dev 0.40-3build1 Β· BSD-2-Clause
- ubuntu noble: publib-dev 0.40-3build1 Β· BSD-2-Clause
- ubuntu questing: publib-dev 0.40-4
- ubuntu resolute: publib-dev 0.40-4build1 Β· BSD-2-Clause
- ubuntu stonking: publib-dev 0.40-4build1 Β· BSD-2-Clause
- Copyright (c) 1994-2006 Lars Wirzenius. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms