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

How would you use the functions fseek(), freed(), fwrite() and ftell()?

0 Answers   Aspire, Infogain, TISL,


Why use int main instead of void main?

0 Answers  


A routine usually part of the operation system that loads a program into memory prior to execution a) linker b) loader c) preprocessor d) compiler

0 Answers  


What are global variables and how do you declare them?

0 Answers  


What do you mean by keywords in c?

0 Answers  


How. To pass the entrance test

1 Answers   Tech Mahindra,


what is mallloc()?how it works?

4 Answers   Excel,


any function have arguments one or more OR not . it is compulsary a) any function compulsary have one or more arguments b) any function did not have arguments. It is not compulsary c) it is optional it is not compulsary d) none of the above

0 Answers  


the maximum length of a character constant can be a) 1 character b) 8 characters c) 256 chaacters d) 125 characters

0 Answers  


What are the different data types in C?

0 Answers  


Was 2000 a leap year?

0 Answers  


Tell me about low level programming languages.

0 Answers   Amdocs,


Categories