strsplit(3)

LIBRARY
#include <xtend/string.h>
-lxtend

SYNOPSIS

int     strsplit(char *string, char ***array, const char *sep)

ARGUMENTS
string  String to be parsed for tokens
array   Pointer array to be filled with tokens
sep     Character string listing all recognized separators

DESCRIPTION
strsplit() splits a string into tokens separated by any character in the string argument sep. The function interface is similar to split() in awk, except that sep is a simple list of characters rather than a regular expression. The array argument should be the address of a char ** variable. strsplit() allocates memory for the pointers as needed and assigns one token to each pointer. strsplit() should only be used when an array of strings representing the tokens is actually needed. In cases where each token can be immediately processed and forgotten, use a loop with strsep(). Introducing arrays into a program unnecessarily should avoided as a habit to maximize speed and minimize memory use. Caution: strsplit() is destructive: It replaces the separators in string with null bytes. To preserve the original string, duplicate it with strdup() first and pass the copy to strsplit().

RETURN VALUES
The number of tokens into which string is separated, or 0 if a memory allocation or other failure occurred.

EXAMPLES
char    *string = "1,2,3,4,5", *copy, **array;
size_t  c, tokens;
copy = strdup(string);
tokens = strsplit(copy, &array, ",");
for (int c = 0; c < tokens; ++c)
    puts(array[c]);

SEE ALSO
strsep(3)