From 8653cc8d0834a1f243b961e3353cfc2ff6358e94 Mon Sep 17 00:00:00 2001 From: pjd Date: Fri, 5 Dec 2008 15:50:59 +0000 Subject: Add an easier example. Reviewed by: trasz --- lib/libc/string/strsep.3 | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/libc/string/strsep.3 b/lib/libc/string/strsep.3 index 919ea3c..9432a88 100644 --- a/lib/libc/string/strsep.3 +++ b/lib/libc/string/strsep.3 @@ -31,7 +31,7 @@ .\" @(#)strsep.3 8.1 (Berkeley) 6/9/93 .\" $FreeBSD$ .\" -.Dd June 9, 1993 +.Dd December 5, 2008 .Dt STRSEP 3 .Os .Sh NAME @@ -81,6 +81,21 @@ returns .Sh EXAMPLES The following uses .Fn strsep +to parse a string, and prints each token in separate line: +.Bd -literal -offset indent +char *token, *string, *tofree; + +tofree = string = strdup("abc,def,ghi"); +assert(string != NULL); + +while ((token = strsep(&string, ",")) != NULL) + printf("%s\en", token); + +free(tofree); +.Ed +.Pp +The following uses +.Fn strsep to parse a string, containing tokens delimited by white space, into an argument vector: .Bd -literal -offset indent -- cgit v1.1