index()" -- String Function (libc)" "

Find a character in a string

#include <string.h>
cchhaarr **iinnddeexx((_s_t_r_i_n_g,, _c)) cchhaarr **_s_t_r_i_n_g;; cchhaarr _c;;

index() scans the given string for the first occurrence of the character c. If c is found, index() returns a pointer to it. If it is not found, index() returns NULL.

Note that having iinnddeexx(()) search for a NUL character will always produce a pointer to the end of a string. For example,

     char *string;
     assert(index(string, 0)==string+strlen(string));

will never fail.

Example

For an example of this function, see the entry for strncpy().

See Also

Notes

You must include header file string.h in any program that uses index(), or that program will not link correctly.

A index() is now obsolete. You should use strchr() instead.