Home / C / Program to find a substring in a given string

Program to find a substring in a given string

This program is to find a substring 1101 in a given string. This is also used for string matching .

#include<stdio.h>
#include<conio.h>

void main()
{
char s[20];
char p[]="1101";
int i, count=0;
clrscr();
printf("enter Your String = ");
scanf("%s",s);
for(i=0;s[i]!='\0';i++)
{
if(s[i]==p[count] )
count++;
else
count=0;
if ( count == 4)
{
printf("\n Substring %s found in the given string", p);
break;
}
}
getch();
}

Output:

find a substring

Check Also

Restrict Mouse Pointer Position C Graphics Program

This C Program will restrict the Mouse Pointer location or to a particular position or x,y ...

Leave a Reply

Your email address will not be published. Required fields are marked *

Preventing spam * Time limit is exhausted. Please reload the CAPTCHA.