CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
using namespace std;
// The strstr() function in C++ finds the first occurrence of a substring in a string.
// finding a string from the total string like brain from "Use your brain and heart"
char* Strstr(const char* s1, const char* s2)
{
if(*s2 == 0)
{
return (char*)s1; // s2 is the empty string
}
for( ; *s1; s1++)
{
if(*s1 == *s2)
{
for(const char* p1=s1, *p2=s2; *p1 == *p2; p1++, p2++ )
{
if(*(p2+1) == 0)
{
return (char*)s1;
}
}
}
}
return 0;
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run