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

What are inbuilt functions in c?

0 Answers  


what is the output of below pgm? void main() { int i=0; if(i) printf("pass"); else printf("fail"); }

4 Answers  


WAP to find that given no is small or capital

3 Answers  


write a program that accepts 3 numbers from the user. dispaly the values in a descending order.

3 Answers  


Tell me what are bitwise shift operators?

0 Answers  






What is data type long in c?

0 Answers  


why arguments can generally be passed to functions a) sending the values of the arguments b) sending the addresses of the arguments c) a & b d) none of the above

0 Answers  


What is the difference between constant pointer and constant variable?

0 Answers   NIIT,


What is the difference between declaring a variable by constant keyword and #define ing that variable?

1 Answers  


What is c method?

0 Answers  


How to write a program for machine which is connected with server for that server automatically wants to catch the time for user of that machine?

0 Answers   Infosys,


Explain that why C is procedural?

0 Answers   Maveric, Verifone,


Categories