rindex(3) CLIX rindex(3)
NAME
rindex - Locates the last occurrence of a character in a string
LIBRARY
Berkeley Software Distribution Library (libbsd.a)
SYNOPSIS
#include <string.h>
char *rindex(
char * string ,
int character );
PARAMETERS
string A pointer to a character string
character
A character
DESCRIPTION
The rindex() function returns a pointer to the last 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 rindex() 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 last comma in `string' */
comma_ptr = rindex(string, comma);
if (! comma_ptr)
printf("There is no comma in the string %s\n", string);
else
printf("The substring which begins with the last comma is %s\n",
2/94 - Intergraph Corporation 1
rindex(3) CLIX rindex(3)
comma_ptr);
}
RETURN VALUES
Upon successful completion, the rindex() function returns a pointer to the
last 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: index(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