

strstr()                 String Function                 strstr()




Find one string within another

#include <string.h>
cchhaarr *ssttrrssttrr(_s_t_r_i_n_g_1, _s_t_r_i_n_g_2);
cchhaarr *_s_t_r_i_n_g_1, *_s_t_r_i_n_g_2;

strstr looks  for string2  within string1.  The  terminating null
character is not considered part of string2.

strstr returns a  pointer to where string2 begins within string1,
or NULL if string2 does not occur within string1.

For example,


        char *string1 = "Hello, world";
        char *string2 = "world";
        strstr(string1, string2);


returns  ssttrriinngg11 plus  seven, which  points  to the  beginning of
wwoorrlldd within HHeelllloo, wwoorrlldd.  On the other hand,


        char *string1 = "Hello, world";
        char *string2 = "worlds";
        strstr(string1, string2);


returns NULL because wwoorrllddss does not occur within HHeelllloo, wwoorrlldd.

***** See Also *****

string functions, string.h






















COHERENT Lexicon                                           Page 1


