rriinnddeexx() -- String Function (libc)

Find rightmost occurrence of a character in a string
#iinncclluuddee <ssttrriinngg.hh>
cchhaarr *rriinnddeexx(_s_t_r_i_n_g, _c) cchhaarr *_s_t_r_i_n_g; cchhaarr _c;

rriinnddeexx()  scans _s_t_r_i_n_g  for the  last occurrence  of character  _c. If  _c is
found, rriinnddeexx()  returns a  pointer to  it.  If it  is not  found, rriinnddeexx()
returns NULL.

_E_x_a_m_p_l_e
This example  uses rriinnddeexx() 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);
}

_S_e_e _A_l_s_o
lliibbcc, ssttrrcchhrr(), ssttrrrrcchhrr(), ssttrriinngg.hh

_N_o_t_e_s
You _m_u_s_t include header file ssttrriinngg.hh in any program that uses rriinnddeexx(), or
that program will not link correctly.

rriinnddeexx() is now obsolete.  You should use ssttrrrrcchhrr() instead.
