Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ index(3C) — DG/UX 4.00

Media Vault

Software Library

Restoration Projects

Artifacts Sought



                                                                index(3C)



        _________________________________________________________________
        index                                                    function
        Search for the first occurrence of a character in astring.
        _________________________________________________________________


        Calling Sequence

        #include <string.h>
        #include <stdio.h>
        char *search, template, *index();
        index(search, template);


          where   search is the character array to inspect.
                  template is the character you want to match.



        Description

        Use the index function to find the first occurrence of a
        specified character in a string.  The include file string.h
        defines this function.  The index function is the same as the
        strchr function.


        Returns

        The function returns a null if the character does not occur in
        the string; otherwise it returns the pointer to the byte it
        found.


        Related Functions

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


        Example

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

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

        char  c, string[MAX], *index();
        int   i = 1, loc;

        main(argc, argv)



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





                                                                index(3C)



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

        If you call the program test with the strings alphabet,
        syllabary, and string, and then respond to the query with the
        character a, you generate the output

        First occurrence of 'a' in
                'alphabet'
        at 34000023356.
        First occurrence of 'a' in
                'syllabary'
        at 34000023362.
        Character 'a' does not occur in
                'string'

        (The locations returned 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