Write a program in C++ returning starting locations of a
substring using pointers
Answer Posted / 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 View All Answers
In what scenario does the Logical file and Physical file being used?
Who created stl?
What does stl stand for in basketball?
Describe how to safeguard a system through acquisition of an antivirus Program and systematic backup.
Describe the My Computer and My Documents folders; identify the elements that are present in every Window.
When did c++ add stl?
To modify an, existing worksheet. What steps are involved for: 1. Inserting and deleting rows and columns. 2. Printing cell formulas 3Jld displayed values 3. Using the page setup command
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
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.
Name the different types of stl containers.
Can we use stl in coding interviews?
What is meant by stl in c++?
Is there any error below, its a code to delete all entires from a map #include
What is stl in c++ with example?
Why should a c++ programmer be interested in stl?