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 ? | 7 Yes | 9 No |
Post New Answer View All Answers
What is stl stack?
Who wrote stl?
Explain stl.
What are stl algorithms?
Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.
How connect plc and pc through software
What are the various types of stl containers?
what is template and type convertion
In what scenario does the Logical file and Physical file being used?
how can u do connectivity in c++ language? plz send me connectivity code in c++ ?
Describe the My Computer and My Documents folders; identify the elements that are present in every Window.
Is stl part of c++ standard?
What does stl stand for in basketball?
Describe how to safeguard a system through acquisition of an antivirus Program and systematic backup.
Q1. A. What is unary operator? List out the different operators involved in the unary operator. B. What is an adjust field format flag? Q2. A. Distinguish between a # include and #define. B. Can a list of string be stored within a two dimensional array? Q3. A.Explain how a pointer to function can be declared in C++? B.List the merits and demerits of declaring a nested class in C++? Q4. A. What are the syntactic rules to be avoid ambiguity in multiple inheritence? B. Explain the operation of overloading of an assignment operator. Q5. A. Explain how the virtual base class is different from the conventional base classes of the opps. B. Explain how an exception handler is defined and invoked in a Program. Q6. A. What is a binary file? List the merits and demerits of the binary file usagein C++. B. Write short notes on Text Manipulation Routines. C. Write bites in Turbo c++ Header (“Include”) Files.