Write a program in C++ returning starting locations of a
substring using pointers
Answer / pramod
#include<stdio.h>
#include<iostream.h>
int main()
{
char* mystrstr(char*,char*);
char str1[20];
char str2[10];
cout<<"\n Enter two strings\t";
cin>>str1>>str2;
cout<<"\nstr1 = "<<str1<<" str2 "<<str2 ;
char* c= mystrstr(str1,str2);
if(c!=NULL)
printf("\nc = %s\n",c);
return 0;
}
char* mystrstr(char* str1, char* str2)
{
char *cp = (char *) str1;
char *s1, *s2;
if ( !*str2 )
return((char *)str1);
while (*cp)
{
s1 = cp;
s2 = (char *) str2;
while ( *s1 && *s2 && !(*s1-*s2) )
{
s1++;
s2++;
}
if (!*s2)
{
printf("\n string found\n");
return(cp);
}
cp++;
}
return(NULL);
}
| Is This Answer Correct ? | 8 Yes | 9 No |
please visit this site you'll find my question this is my homework please answer it if you can http://easyscience.org/ib/lofiversion/index.php/t36168.html
What is the Difference between CArray and CList?
1 Answers ProdEx Technologies, Siemens,
what is c++
sir please send me bpcl previous question papers
0 Answers BPCL Bharat Petroleum,
Define stl.
What is C++ could you enplane me please?
WHAT IS THE DIFFERENCE BETWEEN C++ AND VC++
what is strcture i++ i ++i answer to this i=5 what is the out put
How stl is different from the c++ standard library?
How do I convert a stl file?
What do you mean by stl?
How the STL's are implemented, What the difference between templates and STL?