STRINIT(3pub)

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

okay bestie, welcome to the C Programmer's Manual β€” this one's a lil baby function from publib and it's literally so simple it's giving main character energy for no reason. let's get into it ✨


🌸 NAME 🌸

strinit β€” initialize a string with a given character to a given length πŸŽ€


✨ SYNOPSIS ✨

#include <publib.h>
char *strinit(char *s, int c, size_t len) {
yes the synopsis has a lil stray { on the end, and no we are not gonna touch it, she's iconic like that πŸ’…

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so strinit takes the string that s points to and initializes it to be of length len, with every single character being c.

here's the tea though πŸ«– β€” that terminating '\0' is NOT counted in the length. so the string is actually gonna use len+1 characters. one extra for the null, always, no cap. plan your buffer accordingly bestie, fr fr 😭


πŸŽ€ RETURN VALUE πŸŽ€

strinit will return s. that's it. that's the whole return value. she hands you back the same pointer you gave her. queen behavior πŸ‘‘


🌈 EXAMPLE 🌈

say you wanna initialize a string to consist of twenty underscores. here's how you'd do it:

#include <publib.h>

char string[21];     /* note 21 to make room for '\0' */
strinit(string, '_', 20);

see the 21? that's the 20 plus the extra one for '\0'. not me warning you about this twice but like… please remember the extra byte πŸ’€


πŸ‘‘ SEE ALSO πŸ‘‘


πŸ’œ AUTHOR πŸ’œ

Lars Wirzenius (lars.wirzenius@helsinki.fi) β€” ty for your service king 🫢


Publib Β· C Programmer's Manual Β· STRINIT(3pub)

and that's the whole page bestie!! πŸ’– this came to you straight from the Publib corner of the C Programmer's Manual, section 3pub, written by the legend himself Lars Wirzenius (hi lars πŸ’…). no version number on the tin, just vibes, just strinit. go forth and fill your buffers with underscores πŸŒΈβœ¨πŸ¦‹

πŸ“¦ where this page comes from