xref: /csrg-svn/lib/libc/string/strsep.3 (revision 50757)
148351Scael.\" Copyright (c) 1990, 1991 The Regents of the University of California.
241981Sbostic.\" All rights reserved.
341981Sbostic.\"
441981Sbostic.\" This code is derived from software contributed to Berkeley by
541981Sbostic.\" Chris Torek.
641981Sbostic.\"
7*50757Scael.\" %sccs.include.redist.roff%
841981Sbostic.\"
9*50757Scael.\"	@(#)strsep.3	5.4 (Berkeley) 08/03/91
10*50757Scael.\"
1148351Scael.Dd
1248351Scael.Dt STRSEP 3
1348351Scael.Os
1448351Scael.Sh NAME
1548351Scael.Nm strsep
1648351Scael.Nd separate strings
1748351Scael.Sh SYNOPSIS
1848351Scael.Fd #include <string.h>
1948351Scael.Ft char *
2048351Scael.Fn strsep "char **stringp" "char *delim"
2148351Scael.Sh DESCRIPTION
2248351ScaelThe
2348351Scael.Fn strsep
24*50757Scaelfunction locates in the null-terminated string at
2548351Scael.Fa *stringp
2641981Sbosticthe first occurence of any character in
2748351Scael.Fa delim
2848351Scaeland replaces this with a
2948351Scael.Ql \e0 ,
3041981Sbosticrecords the location of the immediate following character in
3148351Scael.Fa *stringp ,
3241981Sbosticthen returns the original value of
3348351Scael.Fa *stringp .
3441981SbosticIf no delimiter characters are found,
3548351Scael.Fn strsep
3641981Sbosticsets
3748351Scael.Fa *stringp
3848351Scaelto
3948351Scael.Dv NULL ;
4041981Sbosticif
4148351Scael.Fa *stringp
4248351Scaelis initially
4348351Scael.Dv NULL ,
4448351Scael.Fn strsep
4548351Scaelreturns
4648351Scael.Dv NULL .
4748351Scael.Sh EXAMPLES
4841981SbosticThe following uses
4948351Scael.Fn strsep
5041981Sbosticto parse strings containing runs of white space,
5141981Sbosticmaking up an argument vector:
5248351Scael.Bd -literal -offset indent
5341981Sbosticchar inputstring[100];
5441981Sbosticchar **argv[51], **ap = argv, *p, *val;
5548351Scael/* set up inputstring */
5641981Sbosticfor (p = inputstring; p != NULL; ) {
5748351Scael	while ((val = strsep(&p, " \et")) != NULL && *val == '\e0');
5848351Scael	*ap++ = val;
5941981Sbostic}
6041981Sbostic*ap = 0;
6148351Scael.Ed
6248351Scael.Sh HISTORY
6348351ScaelThe
6448351Scael.Fn strsep
6548351Scaelfunction is
6648351Scael.Ud .
67