Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ index(3C) — DG/UX 5.4R3.00

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

reentrant(3)

memchr(3C)

strchr(3C)

strrchr(3C)



index(3C)                      DG/UX 5.4R3.00                      index(3C)


NAME
       index - search for the first occurrence of a character in a string

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

   where:
       search is the character array to inspect.
       template is the character (casted to an int) you want to match.

DESCRIPTION
       Use the index function to find the first occurrence of a specified
       character (which must be casted to an int) in a string.  The include
       file string.h defines this function.  The index function is the same
       as the strchr function.


   Considerations for Threads Programming
                     +---------+-----------------------------+
                     |         |                      async- |
                     |function | reentrant   cancel   cancel |
                     |         |              point    safe  |
                     +---------+-----------------------------+
                     |index    |     Y          N        N   |
                     +---------+-----------------------------+

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)

       int    argc;
       char  *argv[];
       {
           printf("Character template?\n");
           scanf("%c", &c);
           while (i < argc) {
               sprintf(string, "%s", argv[i]);
               if ((loc = index( string, (int) 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",



Licensed material--property of copyright holder(s)                         1




index(3C)                      DG/UX 5.4R3.00                      index(3C)


                          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.)

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

SEE ALSO
       reentrant(3), memchr(3C), strchr(3C), strrchr(3C).































Licensed material--property of copyright holder(s)                         2


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