This HTML automatically generated with rman for NEMO
Table of Contents


burststring - separate a string into tokens, and free them


#include <stdinc.h>string *burststring(str, sep)string *burst2string(str,
sep)string str;string sep;
void freestrings(strptr)string *strptr;


burststring() breaks a string str of words separated by characters in sep into individual strings, and returns them as an extended string (ie, a NULL-terminated sequence of string pointers; see extstring). For example, if str is the string "foo, bar, fum" and sep is the string ", " (note the space after the comma), the result is an array of four pointers; the first three point to strings "foo", "bar", and "fum", and the last one is NULL. burststring calls malloc(3) to obtain memory to hold the results.

burst2string works exactly like burststring, except it now also returns the sep portions. This allows the user to exactly reconstruct the original input string by catenating all the array elements. Useful for editing.

freestrings can be used to free all memory associated with an array of strings, as e.g. allocated by burststring.


    string *sp = burststring("a b c"," ");
    int nsp = xstrlen(sp,sizeof(string))-1;
    for (int i=0; i<nsp; i++)
        printf("sp[%d] = %s\n",i,sp[i]);

Note that unlike strtok(3) , burststring does not modify the input string


The maximum number of words and characters per word is hardcoded as MWRD=2048 and MSTR=256. An alternative would be to recode this using strtok(3) . Some examples of these are in table(3NEMO) .

See Also

extstring(3NEMO) , strtok(3)


Joshua Barnes, Peter Teuben

Update History

2-dec-86    Dark ages version    JEB
16-oct-90    Added freestrings    PJT
26-dec-94    Added burst2string    PJT

Table of Contents