Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

strstr - First occurrence of one string in another

&pagelevel(4)&pagelevel

Definition

#include <string.h>

char *strstr(const char *s1, const char *s2);

strstr searches for the first occurrence of string s2 (without the terminating null byte) in string s1.

Return val.

Pointer to the start of the string found in s1



if s2 is contained in s1.


0

if s2 is not contained in s1.                            


Pointer to the start of s1



if s2 has a length of 0.

Notes

Strings terminated with the null byte are expected as arguments.

The following two prototypes of the strstr function are applicable to C++:
const char *strstr(const char *s1, const char *s2);

         char *strstr( char *s1, const char *s2);

Example

#include <string.h>
#include <stdio.h>
int main(void)
{
   char *s1 = "City: Munich, Name: Peter Mueller";
   char *s2 = "Peter";
   printf("Full name? %s\n", strstr(s1, s2));  /* Peter Mueller */
   return 0;
}

See also

strchr