program to locate string with in a string with using strstr
function

Answers were Sorted based on User's Feedback



program to locate string with in a string with using strstr function..

Answer / pradeep

#include<stdio.h>
#include<string.h>
void main()
{
char *str1,*str2,*ptr;
printf("Enter string1:");
scanf("%s",&str1);
printf("Enter string2:");
scanf("%s",&str2);
ptr=strstr(str1,str2);
if(ptr==0)
printf("String not located");
else
printf("string located are %s",ptr);
}

Is This Answer Correct ?    3 Yes 0 No

program to locate string with in a string with using strstr function..

Answer / gmail

#include<iostream.h>
#include<conio.h>
void main()
{
char str1[15],str2[15];
clrsacr();
cout<<"Enter a string";
cin>>str1;
cout<<"\nEnter another string to be located";
cin>>str2;
int n;
n=strstr(str1,str2);
if(n==0)
cout<<"\nstring not locatd";
else
cout<<"At location "<<(n+1);
getch();
}

Is This Answer Correct ?    3 Yes 6 No

Post New Answer

More C Interview Questions

A program to allow an input operand and operator from the operator and read on the display and output operand.

0 Answers  


Which built-in library function can be used to match a patter from the string?

0 Answers  


what is ans for this scanf(%%d",c);

1 Answers  


What is function pointer and where we will use it

2 Answers   Infosys, NetApp,


How is a two dimensional array passed to function when the order of matrix is not known at complie time?

1 Answers   CSC,


what is a NULL pointer?

2 Answers  


How can you avoid including a header more than once?

0 Answers  


What is the use of a ‘’ character?

0 Answers  


Explain the difference between #include "..." And #include <...> In c?

0 Answers  


What does int main () mean?

0 Answers  


what is data structure

5 Answers   Maveric, TCS,


in case any function return float value we must declare a) the function must be declared as 'float' in main() as well b) the function automatically returned float values c) function before declared 'float' keyword d) all the above

0 Answers  


Categories