while(*(str2)!='\0')//recording max value of 2nd string
{
str2++;
count2_max++;
}
str2 -= count2_max ;
while(*(str1)!='\0')//checking string 1 character by character for if it has string 2 in it.
{
if(*(str2)==*(str1))
{
str2++;
count2++;
}
else
{
if(*(str1)!=*(str1-1))
{
count2=0;
}
}
if(count2 == count2_max)//checking if 2nd string is complete in the first string
{
str1=((str1-count2_max)+1);
return str1 ;
}
str1++;
}
if(*(str1)=='\0')
{
returnNULL;
}
}
int main()
{
char*str1=newchar[100];//The first string
char*str2=newchar[100];//The second string
cout<<"Please Enter the string: ";cin.getline(str1, 100);
cout<<"Now please enter the second string: ";cin.getline(str2, 100);
cout<< endl <<"The pointer to the first occured second string (str2) in the first string (str1) holds the following address: "<<(int*)strstr(str1, str2)<< endl << endl ;
Please Enter the string: Now please enter the second string:
The pointer to the first occured second string (str2) in the first string (str1) holds the following address: 0x8a1000a