1.\" Copyright (c) 1990, 1991 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" Chris Torek. 6.\" 7.\" %sccs.include.redist.roff% 8.\" 9.\" @(#)strsep.3 5.5 (Berkeley) 11/16/91 10.\" 11.Dd 12.Dt STRSEP 3 13.Os 14.Sh NAME 15.Nm strsep 16.Nd separate strings 17.Sh SYNOPSIS 18.Fd #include <string.h> 19.Ft char * 20.Fn strsep "char **stringp" "char *delim" 21.Sh DESCRIPTION 22The 23.Fn strsep 24function locates, in the string referenced by 25.Fa *stringp , 26the first occurrence of any character in the string 27.Fa delim 28(or the terminating 29.Ql \e0 30character) and replaces it with a 31.Ql \e0 . 32The location of the next character after the delimiter character 33(or NULL, if the end of the string was reached) is stored in 34.Fa *stringp . 35The original value of 36.Fa *stringp 37is returned. 38.Pp 39An ``empty'' field, i.e. one caused by two adjacent delimiter characters, 40can be detected by comparing the location referenced by the pointer returned 41in 42.Fa *stringp 43to 44.Ql \e0 . 45.Pp 46If 47.Fa *stringp 48is initially 49.Dv NULL , 50.Fn strsep 51returns 52.Dv NULL . 53.Sh EXAMPLES 54The following uses 55.Fn strsep 56to parse a string, containing tokens delimited by white space, into an 57argument vector: 58.Bd -literal -offset indent 59char **ap, *argv[10], *inputstring; 60 61for (ap = argv; (*ap = strsep(&inputstring, " \et")) != NULL;) 62 if (**ap != '\e0') 63 ++ap; 64.Ed 65.Sh HISTORY 66The 67.Fn strsep 68function 69is intended as a replacement for the 70.Fn strtok 71function. 72While the 73.Fn strtok 74function should be preferred for portability reasons (it conforms to 75.St -ansiC ) 76it is unable to handle empty fields, i.e. detect fields delimited by 77two adjacent delimiter characters, or to be used for more than a single 78string at a time. 79The 80.Fn strsep 81function is 82.Ud . 83