bishalbiswas

second pattern matching algorithm

May 25th, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. int main()
  4. {
  5. int k=0,n,index,i=0;
  6. char s[18][18];
  7. char p[100];
  8. char t[100];
  9.  
  10. gets(p);
  11. gets(t);
  12. n=strlen(t);
  13. strcpy(s[k],"");
  14. while(strcmp(s[k],p)!=0&&k<n)
  15. {
  16. if(t[k]==p[i++])
  17. //if(strcmp(t[k],p[i++])==0)
  18. {
  19. strcat(s[k],t[k]);
  20. strcpy(s[k+1],s[k]);
  21. }
  22. else
  23. {
  24. strcpy(s[k+1],"");
  25. i=0;
  26. }
  27.  
  28. k++;
  29. }
  30.  
  31. if(strcmp(s[k],p)==0)
  32. {
  33. index=k-strlen(p)+1;
  34. }
  35. else
  36. index=0;
  37.  
  38. printf("%d",index);
  39.  
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment