Skip to content

Instantly share code, notes, and snippets.

@Pasi-D
Created May 26, 2017 00:28
Show Gist options
  • Select an option

  • Save Pasi-D/f50254b7bda6a8ea5b9b094f7d18309f to your computer and use it in GitHub Desktop.

Select an option

Save Pasi-D/f50254b7bda6a8ea5b9b094f7d18309f to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
void main(){
int n, m, pos, i;
char text[256], pattern[256];
printf("Enter the text first\n");
gets(text);
n = strlen(text);
printf("Enter the pattern\n");
gets(pattern);
m = strlen(pattern);
int limit = n-m;
if(m > n){
printf("No Pattern found\n");
}else{
for (pos = 0; pos < limit; pos++)
{
for (i = 0; i < m; i++)
{
if (pattern[i] != text[pos+i])
{
break;
}
}
if (i == m)
{
printf("Pattern found at position %d\n", pos );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment