BREAKLINE(3)

πŸ“¦
version 2022.10.16 Β· 2 versions
, in opensuse-leap 16.0

🌸 BREAKLINE(3) β€” SchilyΒ΄s LIBRARY FUNCTIONS 🌸

okay bestie, welcome to the breakline page πŸ’… this one lives in SchilyΒ΄s LIBRARY FUNCTIONS and it's honestly such a vibe once you get it.


✨ NAME ✨

breakline() β€” breaks a buffer into fields πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

int breakline(buf, delim, array, max)
char *buf;
char delim;
char *array[];
int max;

πŸ’– DESCRIPTION πŸ’–

so here's the tea β˜•: breakline() takes the buffer buf and chops it into fields, with the character delim doing the dividing βœ‚οΈ and while it's at it, it replaces every occurrence of delim inside buf with the NULL character ('\0') β€” lowkey destructive but in a cute way 🫢.

Then it fills in array with pointers to the beginning of each field in the buffer. max says how many entries you get to fill in that array, no more, no cap 🧒.

and if buf doesn't have enough fields to go around? the extra entries in array just point to an empty string. everyone gets a seat bestie, even the empties πŸ’€βœ¨


πŸ‘‘ RETURNS πŸ‘‘

returns the number of fields actually in the buffer β€” but never more than max, obviously. periodt 🌈


πŸ“ EXAMPLES πŸ“

okay icon, say you've got this:

char *buf = "a:bc:d:efg";
char *array[10];

breakline(buf, ':', array, 10);

now the : are replaced by '\0' and boom πŸ’₯:

array[0] = "a";
array[1] = "bc";
array[2] = "d"
array[3] = "efg";
array[4] ... array[9] = "";

look at that. iconic behaviour honestly πŸ§šπŸ’œ


πŸŽ€ SEE ALSO πŸŽ€


bestie reminder: this page is from SchilyΒ΄s LIBRARY FUNCTIONS, written by Joerg Schilling, dated 2022/09/09 β€” go off and break some lines responsibly πŸ’– slay βœ¨πŸ¦‹
πŸ“¦ where this page comes from