

rindex()                 String Function                 rindex()




Find a character in a string

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;

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 rriinnddeexx to help  strip a sample file name of the
path information.


#include <stdio.h>
#define PATHSEP '/' /* path name separator */



extern char *rindex();
extern char *basename();



main()
{



    printf("Before massaging: %s\n", testpath);
    printf("After massaging: %s\n", basename(testpath));
}



char *basename(path)
char *path;
{
    char *cp;
    return (((cp = rindex(path, PATHSEP)) == NULL)
                     ? path : ++cp);
}


***** See Also *****

index(), string functions

***** Notes *****

This  function is  identical to  the  function strrchr,  which is
described in the ANSI standard.




COHERENT Lexicon                                           Page 1




rindex()                 String Function                 rindex()



COHERENT includes  strrchr in  its libraries.  It  is recommended
that it  be used instead of rindex so  that programs more closely
approach strict conformity with the ANSI standard.






















































COHERENT Lexicon                                           Page 2


