COHERENT manpages
This page displays the COHERENT manpage for rindex() [Find rightmost occurrence of a character in a string].
List of available manpages
Index
rindex() -- String Function (libc)
Find rightmost occurrence of a character in a string
#include <string.h>
char *rindex(string, c) char *string; char c;
rindex() scans string for the last occurrence of character c. If c is
found, rindex() returns a pointer to it. If it is not found, rindex()
returns NULL.
Example
This example uses rindex() to help strip a sample file name of the path
information.
#include <stdio.h>
#include <string.h>
#include <misc.h>
#define PATHSEP '/' /* path name separator */
main()
{
char *testpath = "/foo/bar/baz";
printf("Before massaging: %s\n", testpath);
printf("After massaging: %s\n", basename(testpath));
return(EXIT_SUCCESS);
}
char *basename(path)
char *path;
{
char *cp;
return (((cp = rindex(path, PATHSEP)) == NULL)
? path : ++cp);
}
See Also
libc,
strchr(),
strrchr(),
string.h
Notes
You must include header file string.h in any program that uses rindex(), or
that program will not link correctly.
rindex() is now obsolete. You should use strrchr() instead.











