Print this page
Minor markup tweaks (Sy instead of Nm).
first round of POSIX 2008 stuff
   1 '\" te
   2 .\"  Copyright (c) 2002, Sun Microsystems, Inc. All Rights Reserved  Portions Copyright (c) 1992, X/Open Company Limited  All Rights Reserved
   3 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
   4 .\" http://www.opengroup.org/bookstore/.
   5 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
   6 .\"  This notice shall appear on any product containing this material.
   7 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
   8 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
   9 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
  10 .TH INDEX 3C "Jul 24, 2002"
  11 .SH NAME
  12 index, rindex \- string operations
  13 .SH SYNOPSIS
  14 .LP
  15 .nf
  16 #include <strings.h>
  17 
  18 \fBchar *\fR\fBindex\fR(\fBconst char *\fR\fIs\fR, \fBint\fR \fIc\fR);
  19 .fi
  20 
  21 .LP
  22 .nf
  23 \fBchar *\fR\fBrindex\fR(\fBconst char *\fR\fIs\fR, \fBint\fR \fIc\fR);
  24 .fi
  25 
  26 .SH DESCRIPTION
  27 .sp
  28 .LP
  29 The \fBindex()\fR and \fBrindex()\fR functions operate on null-terminated
  30 strings.
  31 .sp
  32 .LP
  33 The \fBindex()\fR function returns a pointer to the first occurrence of
  34 character \fIc\fR in string \fIs\fR.
  35 .sp
  36 .LP
  37 The \fBrindex()\fR function returns a pointer to the last occurrence of
  38 character \fIc\fR in string \fIs\fR.
  39 .sp
  40 .LP
  41 Both \fBindex()\fR and  \fBrindex()\fR return a null pointer if \fIc\fR does










  42 not occur in the string. The null character terminating a string is considered
  43 to be part of the string.
  44 .SH USAGE
  45 .sp
  46 .LP
  47 On most modern computer systems, you can \fInot\fR use a null pointer to
  48 indicate a null string.  A null pointer is an error and results in an abort of
  49 the program.  If you wish to indicate a null string, you must use a pointer
  50 that points to an explicit null string.  On some machines and with some
  51 implementations of the C programming language, a null pointer, if dereferenced,
  52 would yield a null string.  Though often used, this practice is not always
  53 portable. Programmers using a null pointer to represent an empty string should
  54 be aware of this portability issue.  Even on machines where dereferencing a
  55 null pointer does not cause an abort of the program, it does not necessarily
  56 yield a null string.
  57 .SH ATTRIBUTES
  58 .sp
  59 .LP
  60 See \fBattributes\fR(5) for descriptions of the following attributes:
  61 .sp
  62 
  63 .sp
  64 .TS
  65 box;
  66 c | c
  67 l | l .
  68 ATTRIBUTE TYPE  ATTRIBUTE VALUE
  69 _
  70 Interface Stability     Standard
  71 .TE
  72 
  73 .SH SEE ALSO
  74 .sp
  75 .LP
  76 \fBbstring\fR(3C), \fBmalloc\fR(3C), \fBstring\fR(3C), \fBattributes\fR(5),
  77 \fBstandards\fR(5)

   1 .\"  Copyright (c) 2002, Sun Microsystems, Inc. All Rights Reserved  Portions Copyright (c) 1992, X/Open Company Limited  All Rights Reserved
   2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
   3 .\" http://www.opengroup.org/bookstore/.
   4 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
   5 .\"  This notice shall appear on any product containing this material.
   6 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
   7 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
   8 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
   9 .Dd "Jul 20, 2014"
  10 .Dt INDEX 3C
  11 .Os
  12 .Sh NAME
  13 .Nm index, rindex
  14 .Nd locate character in string
  15 .Sh SYNOPSIS
  16 .In strings.h
  17 .Ft char *
  18 .Fn index "const char *s" "int c"
  19 .Ft char *
  20 .Fn rindex "const char *s" "int c"
  21 .Sh DESCRIPTION
  22 The
  23 .Fn index
  24 and
  25 .Fn rindex
  26 functions operate on null-terminated strings.
  27 .Lp
  28 The
  29 .Fn index
  30 function returns a pointer to the first occurrence of
  31 character
  32 .Fa c
  33 in string
  34 .Fa s .
  35 .Lp
  36 The
  37 .Fn rindex
  38 function returns a pointer to the last occurrence of
  39 character
  40 .Fa c
  41 in string
  42 .Fa s .
  43 .Lp
  44 Both
  45 .Fn index
  46 and
  47 .Fa rindex
  48 return a null pointer if
  49 .Fa c
  50 does
  51 not occur in the string. The null character terminating a string is considered
  52 to be part of the string.
  53 .Sh USAGE
  54 The
  55 .Xr strchr 3C
  56 and
  57 .Xr strrchr 3C
  58 should be used in portable applications; those functions are specified in
  59 .St -isoC
  60 whereas these are not.
  61 .Sh INTERFACE STABILITY
  62 .Sy Obsolete Standard .
  63 .Sh MT-LEVEL
  64 .Sy Async-Signal-Safe .
  65 .Sh SEE ALSO
  66 .Xr bstring 3C ,
  67 .Xr malloc 3C ,
  68 .Xr string 3C ,
  69 .Xr standards 5
  70 .Sh STANDARDS
  71 These functions were part of
  72 .At v6 ,
  73 were added in
  74 .St -p1003.1-2001 ,
  75 and subsequently removed from
  76 .St -p1003.1-2008 .