Write code to check if a string contains a substring. Click for Solution |
-
Warning: Illegal string offset 'name' in /home/prepdo6/gpl4you/discussquessub.php on line 681
A #include <stdio.h>
int compare(char *p, char *s)
{
char *prev,*beg;
while(*p)
{
if(*p==*s)
{
prev=p;
beg=s;
while(*s)
{
if(*p!=*s)
{
p=prev;
s=beg;
break;
}
else
{
p++;
s++;
}
}
if(*s=='\0')
return 1;
}
p++;
}
return 0;
}
void main()
{
int y;
char *p,*s;
char a[20]="Raktimktir";
char b[20]="ktir";
p=a;
s=b;
y=compare(a,b);
if(y==0)
printf("NOT FOUND\n");
else
printf("FOUND\n");
}
Explore
- GPL4you
- Home
- Prepdoor - Online Mock Test
- About
- FAQs
- Contact
- Contact Us
© 2011 - gpl4you | All Rights Reserved.