373bc2c4807773faab06625fe2f7bfd0f44d6ce3
[unix-history] / usr / src / lib / libc / string / strsep.3
.\" Copyright (c) 1990, 1991 The Regents of the University of California.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Chris Torek.
.\"
.\" %sccs.include.redist.roff%
.\"
.\" @(#)strsep.3 5.4 (Berkeley) %G%
.\"
.Dd
.Dt STRSEP 3
.Os
.Sh NAME
.Nm strsep
.Nd separate strings
.Sh SYNOPSIS
.Fd #include <string.h>
.Ft char *
.Fn strsep "char **stringp" "char *delim"
.Sh DESCRIPTION
The
.Fn strsep
function locates in the null-terminated string at
.Fa *stringp
the first occurence of any character in
.Fa delim
and replaces this with a
.Ql \e0 ,
records the location of the immediate following character in
.Fa *stringp ,
then returns the original value of
.Fa *stringp .
If no delimiter characters are found,
.Fn strsep
sets
.Fa *stringp
to
.Dv NULL ;
if
.Fa *stringp
is initially
.Dv NULL ,
.Fn strsep
returns
.Dv NULL .
.Sh EXAMPLES
The following uses
.Fn strsep
to parse strings containing runs of white space,
making up an argument vector:
.Bd -literal -offset indent
char inputstring[100];
char **argv[51], **ap = argv, *p, *val;
/* set up inputstring */
for (p = inputstring; p != NULL; ) {
while ((val = strsep(&p, " \et")) != NULL && *val == '\e0');
*ap++ = val;
}
*ap = 0;
.Ed
.Sh HISTORY
The
.Fn strsep
function is
.Ud .