Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought


rindex()                 String Function                 rindex()




Find a character in a string

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>
#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


Typewritten Software • bear@typewritten.org • Edmonds, WA 98026