index(3) CLIX index(3)
NAME
index - Locates the first occurrence of a character in a string
LIBRARY
Berkeley Software Distribution Library (libbsd.a)
SYNOPSIS
#include <string.h>
char *index(
char * string ,
int character );
PARAMETERS
string A pointer to a character string
character
A character
DESCRIPTION
The function described in this reference manual entry is based in the
Berkeley Software Distribution Library (libbsd.a). For information about
the index() function based in the Programmer's Workbench Library
(libPW.a), see the other index(3) reference manual entry.
The index() function returns a pointer to the first occurrence of the
character specified by the character parameter (converted to char) in the
null-terminated string specified by the string parameter. It returns a
NULL pointer if character does not occur in the string. If character is
'\0', the index() function locates the terminating '\0'.
EXAMPLES
#include <stdio.h>
#include <string.h>
main()
{
int comma;
char *string;
char *comma_ptr;
string = "abc, def, hello";
comma = (int)`,';
/* This call will return a pointer to the first comma in `string' */
comma_ptr = index(string, comma);
2/94 - Intergraph Corporation 1
index(3) CLIX index(3)
if (! comma_ptr)
printf("There is no comma in the string %s\n", string);
else
printf("The substring which begins with the first comma is %s\n",
comma_ptr);
}
RETURN VALUES
Upon successful completion, the index() function returns a pointer to the
first occurrence of the character character in string string. If the
character specified by parameter character is not found, a NULL pointer is
returned.
RELATED INFORMATION
Functions: rindex(3), strcat(3), strchr(3), strcmp(3), strcspn(3),
strcpy(3), strlen(3), strncat(3), strncmp(3), strncpy(3), strpbrk(3),
strrchr(3), strspn(3)
2 Intergraph Corporation - 2/94