#include<stdio.h>
#include<conio.h>
int main()
{
char s1[20],s2[10]; int i,j,flag;
printf("Search a string in another string..\n\n");
printf("Enter the main string: ");
gets(s1);
printf("Enter the sub string: ");
gets(s2);
i=j=flag=0;
while(s1[i]!=0)
{
if(s1[i]==s2[j])
{
while(s2[j]!=0 && s1[i+j]==s2[j])
{
j++;
}
if(s2[j]==0)
{
flag=1;
break;
}
else
j=0;
}
i++;
}
if(flag==1)
printf("Found at no %d",i+1);
else
printf("Not found");
return 0;
}
#include<conio.h>
int main()
{
char s1[20],s2[10]; int i,j,flag;
printf("Search a string in another string..\n\n");
printf("Enter the main string: ");
gets(s1);
printf("Enter the sub string: ");
gets(s2);
i=j=flag=0;
while(s1[i]!=0)
{
if(s1[i]==s2[j])
{
while(s2[j]!=0 && s1[i+j]==s2[j])
{
j++;
}
if(s2[j]==0)
{
flag=1;
break;
}
else
j=0;
}
i++;
}
if(flag==1)
printf("Found at no %d",i+1);
else
printf("Not found");
return 0;
}
No comments:
Post a Comment