Write a program in C++ returning starting locations of a
substring using pointers



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 ?    7 Yes 9 No

Post New Answer

More STL Interview Questions

what are you now programming Languages C+

1 Answers   HCL,


what's the difference between abstract class and concreate class? what's the meaning of standard template library(STL)?

2 Answers  


What is a standard template library (stl)? What are the various types of stl containers?

0 Answers  


what is c++

2 Answers  


What is the stl, standard template library?

0 Answers  






Do you like to Submit Questions in Bulk under Same Category?? Then use our Bulk ListerDo you like to Submit Questions in Bulk under Same Category?? Then use our Bulk Lister

0 Answers  


Why should a c++ programmer be interested in stl?

0 Answers  


What is the name of your birth place?

0 Answers  


write a c++ program to create an object of a class called employee containing the employee code name designation basic salarry HRA Da gross salary as data 10 such objects "members process "

1 Answers  


wap in c++ which accept a integer array and its size as argument and replaces element having even values with its half and element having odd values with twice its value

1 Answers  


Who wrote stl?

0 Answers  


What is stl in oop?

0 Answers  


Categories