Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Post New Answer

More STL Interview Questions

give me the defination of inheritance?

5 Answers   Infosys,


Difference between Structure and Class in C++?

5 Answers   Caritor,


differentiate between private, public and protected data members of the class using example.

1 Answers  


What is stl in oop?

0 Answers  


How does an stl file work?

0 Answers  


In what scenario does the Logical file and Physical file being used?

0 Answers   informatics,


Explain References in C++

3 Answers  


WHAT IS FIBONACCI SERIES?

4 Answers   Stewart,


How do you convert stl to steps?

0 Answers  


How can you create a bulleted list, numbered list and an outline by using bullets and numbering command. Explain with the help of example.

0 Answers  


write a program that will accept a number and print.its equivalent in words the maximum input number is 9999

0 Answers  


Name the different types of stl containers.

0 Answers  


Categories