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

Every time i run a c-code in editor, getting some runtime error and editor is disposing, even after reinstalling the software what may be the problem?

2 Answers  


write a program to display & create a rational number

1 Answers   HCL, TCS,


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

0 Answers  


How is a null pointer different from a dangling pointer?

0 Answers  


How many bytes is a struct in c?

0 Answers  


what is structuer?

4 Answers   LG Soft, Wipro,


How are Structure passing and returning implemented by the complier?

0 Answers   TISL,


write a c program for print your name .but,your name may be small letter mean print a capital letter or your name may be capital letter mean print a small letter .example \\enter ur name : sankar The name is: SANKAR (or) enter your name:SAnkar The name is:saNKAR

5 Answers  


what is the difference between static variable and register variable?

3 Answers  


What is the memory allocated by the following definition ? int (*x)[10];

4 Answers   ADITI, Wipro,


what is the maximum limit of row and column of a matrix in c programming. in linux .

4 Answers   NIIT,


Which of these statements are false w.r.t File Functions? i)fputs() ii)fdopen() iii)fgetpos() iv)ferror() A)ii B)i,ii C)iii D)iv

6 Answers   Accenture,


Categories