Skip to content

Instantly share code, notes, and snippets.

@SwadhInz
Created August 20, 2015 08:54
Show Gist options
  • Save SwadhInz/f3672647fdecdcd1f357 to your computer and use it in GitHub Desktop.
Save SwadhInz/f3672647fdecdcd1f357 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
int main()
{
char txt[100], pat[100];
int k, i, plen, b;
gets(txt);
gets(pat);
plen = strlen(pat);
b = 0;
for(i = 0; txt[i] != '\0'; i++) {
if(pat[0] == txt[i]) {
for(k = 1; pat[k] != '\0'; k++) {
if(pat[k] != txt[i+k])
break;
if(k == plen-1) {
if(!b) {
printf("Pattern found at position: %d", i+1);
b = 1;
}
else
printf(", %d", i+1);
}
}
}
}
if(!b)
puts("Not found!");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment