1#include <iostream>
2#include <string.h>
3
4using namespace std;
5int main() {
6 char str1[] = "Apples are red";
7 char str2[] = "are";
8 char *ptr;
9 ptr = strstr(str1, str2);
10
11 if(ptr)
12 cout<<"Occurance of \""<< str2 <<"\" in \""<< str1 <<"\" is at position "<<ptr - str1 + 1;
13
14 else
15 cout<<"There is no occurance of \""<< str2 <<"\" in "<<str1;
16 return 0;
17}
1/* strstr example */
2#include <stdio.h>
3#include <string.h>
4
5int main ()
6{
7 char str[] ="This is a simple string";
8 char * pch;
9 pch = strstr (str,"simple");
10 strncpy (pch,"sample",6);
11 puts (str);
12 return 0;
13}