Created
May 26, 2017 00:28
-
-
Save Pasi-D/f50254b7bda6a8ea5b9b094f7d18309f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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