index(3c) DG/UX 4.30 index(3c)
NAME
index - Search for the first occurrence of a character in a
string.
SYNOPSIS
#include <string.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 NULL if the character does not occur in
the string; otherwise it returns the pointer to the byte it
found.
SEE ALSO
memchr(3C), strchr(3C), strrchr(3C).
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, 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) Page 1
index(3c) DG/UX 4.30 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.)
Licensed material--property of copyright holder(s) Page 2