Table of Contents

Name

burststring - separate a string into tokens, and free them

Synopsis


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

Description

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.

See Also

extstring(3NEMO)

Author

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