DragonFly On-Line Manual Pages

Search: Section:  


getfields(l)                    BEGEMOT Library                   getfields(l)

NAME

getfields, getmfields, setfields - split string into fields

SYNOPSIS

# include <begemot.h> int getfields(char *str, char **fields, int nfields); int getmfields(char *str, char **fields, int nfields); char *setfields(char *delim);

DESCRIPTION

getfields and getmfields split the input string in substrings as defined by a set of delimiting characters. The pointer array fields is filled with pointers to the starts of the substrings. Each substring is terminated with a NUL character (the original string is modified). The number of entries in the array is given with nfields. If the string contains more substrings than nfields specifies, the last pointer in fields will point to the rest of the string. If there are lesser substrings than entries in fields, the substring pointer array will be NULL terminated. Both functions return the number of substrings found. getfields and getmfields differ in the interpretation of multiple delimiting characters. getfields interprets two consecutive delimiters as an empty field, whereas getmfields collapses multiple delimiters. setfields sets a new set of delimiters. A string containing the old delimiting characters is returned. The default set is "\t ". The NUL character is always interpreted as a delimiter and end of string.

RETURN VALUE

getfields and getmfields return the number of substrings. setfields returns a pointer to static memory containing the old delimiting characters. This is valid only until the next call to setfields and can directly be feed into the next setfields call.

SEE ALSO

strtok(3),

BUGS

Could, perhaps, be more performant. BEGEMOT 12 Sep 1996 getfields(l)

Search: Section: