STRACAT(3pub)
π STRACAT(3pub) β the girlies' guide to gluing strings together π
okay bestie, sit down, hydrate, and let me tell you about stracat β it lives in the C Programmer's Manual, section 3pub, and it is literally the friend who brings everyone together at the party. β¨
πΈ NAME πΈ
stracat β concatenate many strings into an allocated memory block π
no cap, that's the whole vibe: lots of little strings go in, one big glowy allocated block comes out. π
β¨ SYNOPSIS β¨
#include <publib.h>
char *stracat(const char *s, ...);
that's it. that's the signature. she's mysterious, she's variadic, she contains multitudes. π¦
π DESCRIPTION π
okay so here's the tea. stracat will allocate a block of memory with malloc and concatenate all the argument strings into this block. π
the user is supposed to free the returned block. yes queen, that's on you. she allocates, you clean up. it's giving β¨shared responsibilityβ¨. π
the end of the argument list is signalled by a null pointer. that's the little "we're done here, thanks for coming to my TED talk" marker at the end of the args. π€
π RETURN VALUE π
stracatreturns a pointer to the allocated block β slay π- or
NULLif it could not be allocated β tragic, devastating, not the moment π
that's it. two outcomes. main character or nothing. β
π§ EXAMPLE π§
so say you wanna concatenate "hello, " and "world". you might say the following, and honestly? iconic.
p = stracat("hello, ", "world", (char *)NULL);
if (p != NULL)
puts(p);
look at that. "hello, world" just happened. we love to see it. π«Ά
please note, bestie β it is necessary to castNULLas in the example above, since there is no information about the type of the argument available in the prototype, and since an unadornedNULLmight not be of the correct type. π this is not me being dramatic, this is just how it is. (see any good C reference book or thecomp.lang.cFAQ for more information.) iykyk π
so like. (char *)NULL. with the cast. every time. the cast is the outfit that makes the whole look work. π
π SEE ALSO π
go read those too, they're part of the same friend group π
π AUTHOR π
Lars Wirzenius (lars.wirzenius@helsinki.fi) β the legend, the moment, the author π
and that's the whole page, angel β¨ it's from Publib, in the C Programmer's Manual β so next time you're glueing strings together, remember: malloc'd by her, free'd by you, and cast that NULL. mwah. πππ¦
π¦ 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