Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>strstr() find substring</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 strstr()                Find Substring

 #include   <string.h>                   Required for declarations only

 char       *strstr(string1,string2);
 const char *string1;                    String to search
 const char *string2;                    Substring to search for


    strstr() searches 'string1' for the first occurrence of 'string2'.

    Returns:    A pointer to the first occurrence of 'string2' in
                'string1'. NULL is returned if 'string2' is not found.

   -------------------------------- Example ---------------------------------

    The following statements search for 'str2' in 'str1'.

           #include <string.h>
           #include <stdio.h>

           char *str1 = "An ounce of prevention";
           char *str2 = "ounce";
           char *substr;

           main()
           {
               substr = strstr(str1,str2);
               if (substr != NULL)
                   printf("%s",substr);
           }


See Also: strspn() strcspn()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson