index() — Search for character
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4.2 |
both |
Format
#define _XOPEN_SOURCE_EXTENDED 1
#include <strings.h>
char *index(const char *string, int c);
General description
The index() function locates the first occurrence of c (converted to an unsigned char) in the string pointed to by string. The character c can be the NULL character (\0); the ending NULL is included in the search.
The string argument to the function must contain a NULL character (\0) marking the end of the string.
The index() function is identical to strchr() — Search for character.
Note: The
index() function has been moved to the Legacy Option group in Single UNIX Specification, Version 3 and
may be withdrawn in a future version. The strchr() function is preferred
for portability.
Returned value
If successful, index() returns a pointer to the first occurrence of c (converted to an unsigned character) in the string pointed to by string.
If unsuccessful because c was not found, index() returns a NULL pointer.
There are no errno values defined.