#include<stdio.h>
#include<conio.h>
#include<string.h>
int string(char[],char[]);
int main()
{
char str[100],find[20];
int i;
clrscr();
printf("Enter the string :");
gets(str);
printf("Enter the srting that you want to find : ");
gets(find);
i=string(str,find);
if(i==1)
printf("%s is found in %s",find,str);
else
printf("%s is not found in %s",find,str);
getch();
return 0;
}
int string(char str[20], char find[20])
{
int i,j,flag;
for(i=0;str[i];i++)
{
if(str[i]==find[0])
{
flag=1;
for(j=1;find[j];j++)
{
if(str[i+j]!=find[j])
{
flag=0;
break;
}
}
if(flag==1)
break;
}
}
return flag;
}
Output:
Enter the string :radhe
Enter the string that you want to find : r
r is found in string
Enter the string :kano
Enter the string that you want to find : z
z is not found in kano
#include<conio.h>
#include<string.h>
int string(char[],char[]);
int main()
{
char str[100],find[20];
int i;
clrscr();
printf("Enter the string :");
gets(str);
printf("Enter the srting that you want to find : ");
gets(find);
i=string(str,find);
if(i==1)
printf("%s is found in %s",find,str);
else
printf("%s is not found in %s",find,str);
getch();
return 0;
}
int string(char str[20], char find[20])
{
int i,j,flag;
for(i=0;str[i];i++)
{
if(str[i]==find[0])
{
flag=1;
for(j=1;find[j];j++)
{
if(str[i+j]!=find[j])
{
flag=0;
break;
}
}
if(flag==1)
break;
}
}
return flag;
}
Output:
Enter the string :radhe
Enter the string that you want to find : r
r is found in string
Enter the string :kano
Enter the string that you want to find : z
z is not found in kano
No comments:
Post a Comment