Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ rindex(3C) — DG/UX 4.00

Media Vault

Software Library

Restoration Projects

Artifacts Sought



                                                               rindex(3C)



        _________________________________________________________________
        rindex                                                   function
        Search for the last occurrence of a character in a string.
        _________________________________________________________________


        Calling Sequence

        char *search, c, *rindex(), *result;
        result = rindex(search, c);


          where   search is the string to inspect.
                  c is the character you want to match.



        Description

        Use the rindex function to find the last occurrence of a
        specified character in a string.  This function is the same as
        the strrchr function.

        The include file string.h defines this function.


        Returns

        The rindex function returns a null if the character does not
        occur in the string.  Otherwise it returns a pointer to the last
        occurrence of the character.


        Related Functions

        See also the index, memchr, strchr, and strrchr functions.


        Example

        /* Program test for the rindex() function */

        #include <string.h>
        #include <stdio.h>
        #define MAX     80

        char  c, string[MAX], *rindex();
        int   result, i = 1;

        main(argc, argv)




        DG/UX 4.00                                                 Page 1
               Licensed material--property of copyright holder(s)





                                                               rindex(3C)



        int    argc;
        char  *argv[];
        {
            printf("Character template?\n");
            scanf("%c", &c);
            while (i < argc) {
                sprintf(string, "%s", argv[i]);
                if ((result = strrchr(string, c)) == NULL)
                    printf("Character '%c' does not occur in \n\t'%s'\n",
                    c, string);
                else
                    printf("Last occurrence of '%c' in\n\t'%s'\nat %o.\n",
                    c, string, result);
                i++;
            }
        }

        A call to the program test with the strings element, digital, and
        execute generates the output

        Character template?
        e
        Last occurrence of 'e' in
                'element'
        at 34000023362.
        Character 'e' does not occur in
                'digital'
        Last occurrence of 'e' in
                'execute'
        at 34000023364.

        (The locations will vary with execution.)






















        DG/UX 4.00                                                 Page 2
               Licensed material--property of copyright holder(s)



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