summaryrefslogtreecommitdiff
path: root/lib/libc/string/strcspn.3
diff options
context:
space:
mode:
authorRay Lai <ray@cvs.openbsd.org>2007-08-08 07:20:46 +0000
committerRay Lai <ray@cvs.openbsd.org>2007-08-08 07:20:46 +0000
commit1ef73ccec2927bf811545c08c0f5fe66d0780cff (patch)
tree0c102b47b69d3082e858566b728e40be602c3daa /lib/libc/string/strcspn.3
parent93f0a93ea70527771e250436883680a24a846799 (diff)
Show how to use strcspn(3) to trim newlines.
OK jmc and millert.
Diffstat (limited to 'lib/libc/string/strcspn.3')
-rw-r--r--lib/libc/string/strcspn.316
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/libc/string/strcspn.3 b/lib/libc/string/strcspn.3
index c5d9e562d25..21c727344dd 100644
--- a/lib/libc/string/strcspn.3
+++ b/lib/libc/string/strcspn.3
@@ -29,9 +29,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $OpenBSD: strcspn.3,v 1.8 2007/05/31 19:19:32 jmc Exp $
+.\" $OpenBSD: strcspn.3,v 1.9 2007/08/08 07:20:45 ray Exp $
.\"
-.Dd $Mdocdate: May 31 2007 $
+.Dd $Mdocdate: August 8 2007 $
.Dt STRCSPN 3
.Os
.Sh NAME
@@ -72,6 +72,18 @@ size_t span;
span = strcspn(s, charset);
.Ed
+.Pp
+The following removes the first (if any) newline character from string
+.Fa line .
+This is useful for trimming the newline after a
+.Xr fgets 3
+call.
+.Bd -literal -offset indent
+char line[BUFSIZ];
+
+if (fgets(line, sizeof(line), fp) != NULL)
+ line[strcspn(line, "\en")] = '\e0';
+.Ed
.Sh SEE ALSO
.Xr memchr 3 ,
.Xr strchr 3 ,