Browse Source

Show how to use strcspn(3) to trim newlines.

OK jmc and millert.
OPENBSD_4_2
ray 17 years ago
parent
commit
e35f6842e2
1 changed files with 14 additions and 2 deletions
  1. +14
    -2
      src/lib/libc/string/strcspn.3

+ 14
- 2
src/lib/libc/string/strcspn.3 View File

@ -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 ,


Loading…
Cancel
Save