Go to main content

man pages section 3: Basic Library Functions

Exit Print View

Updated: Wednesday, July 27, 2022
 
 

index(3C)

Name

index, rindex - string operations

Synopsis

#include <strings.h>

char *index(const char *s, int c);
char *rindex(const char *s, int c);

Description

The index() and rindex() functions operate on null-terminated strings.

The index() function returns a pointer to the first occurrence of character c in string s.

The rindex() function returns a pointer to the last occurrence of character c in string s.

Both index() and rindex() return a null pointer if c does not occur in the string. The null character terminating a string is considered to be part of the string.

Usage

These functions are provided for compatibility with older code. The strchr() and strrchr() functions defined by the C standards are more portable and preferred in newly written code.

Attributes

See attributes(7) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Interface Stability
Committed
MT-Level
Async-Signal-Safe
Standard
  • POSIX.1-2001,
  • SUS through SUSv3,
  • XPG4v2 through XPG6

See Also

bstring(3C), strchr(3C), attributes(7), standards(7)

History

The index() and rindex() functions were added to libc in the Solaris 2.5 release. In Solaris 2 releases prior to 2.5 they were in the libucb library.