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

Write a program to print factorial of given number using recursion?

0 Answers  


find largest of 3 no

8 Answers  


i have a written test in tomorrow

1 Answers   NNN, Value Labs,


hello freinds next week my interview in reliance,nybody has an idea about it intervew questions..so tell

0 Answers   Reliance,


What is the package for freshers(Non IIT) in amazon(hyderabad). And what is the same for those who are a contract employee.

0 Answers  






Why is event driven programming or procedural programming, better within specific scenario?

0 Answers   Wipro,


What is a lvalue

0 Answers   Global Logic,


How do I determine whether a character is numeric, alphabetic, and so on?

0 Answers  


array of pointer pointer to array pointer to pointer

1 Answers   MAHINDRA,


What is the difference b/w Structure & Array?

6 Answers  


Difference between exit() and _exit() function?

0 Answers  


How can you allocate arrays or structures bigger than 64K?

0 Answers  


Categories