fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int bm_match(const char txt[], const char pat[])
  5. {
  6. int pt;
  7. int pp;
  8. int txt_len = strlen(txt);
  9. int pat_len = strlen(pat);
  10. int skip[256];
  11.  
  12. for (pt = 0; pt <= 255; pt++)
  13. skip[pt] = pat_len;
  14. for (pt = 0; pt < pat_len - 1; pt++)
  15. skip[pat[pt]] = pat_len - pt - 1;
  16.  
  17. while (pt < txt_len) {
  18. pp = pat_len - 1;
  19.  
  20. while (_print(txt, pat, txt_len, pat_len, pt, pp), txt[pt] == pat[pp]) {
  21. if (pp == 0)
  22. return pt;
  23. pp--;
  24. pt--;
  25. }
  26. pt += (skip[txt[pt]] > pat_len - pp) ? skip[txt[pt]] : pat_len - pp;
  27. }
  28.  
  29. return -1;
  30. }
  31.  
  32. int main(void)
  33. {
  34. int idx;
  35. char s1[256]; /* 텍스트 */
  36. char s2[256]; /* 패턴 */
  37.  
  38. puts("Boyer-Moore법");
  39.  
  40. printf("텍스트: ");
  41. scanf("%s", s1);
  42.  
  43. printf("패턴: ");
  44. scanf("%s", s2);
  45.  
  46. idx = bm_match(s1, s2);
  47.  
  48. if (idx == -1)
  49. puts("텍스트에 패턴이 없습니다.");
  50. else
  51. printf("%d번째 문자와 일치합니다.\n", idx + 1);
  52.  
  53. return 0;
  54. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘bm_match’:
prog.c:15:7: warning: array subscript has type ‘char’ [-Wchar-subscripts]
   skip[pat[pt]] = pat_len - pt - 1;
       ^
prog.c:20:10: warning: implicit declaration of function ‘_print’; did you mean ‘vprintf’? [-Wimplicit-function-declaration]
   while (_print(txt, pat, txt_len, pat_len, pt, pp), txt[pt] == pat[pp]) {
          ^~~~~~
          vprintf
prog.c:26:14: warning: array subscript has type ‘char’ [-Wchar-subscripts]
   pt += (skip[txt[pt]] > pat_len - pp) ? skip[txt[pt]] : pat_len - pp;
              ^
prog.c:26:46: warning: array subscript has type ‘char’ [-Wchar-subscripts]
   pt += (skip[txt[pt]] > pat_len - pp) ? skip[txt[pt]] : pat_len - pp;
                                              ^
prog.c: In function ‘main’:
prog.c:41:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", s1);
  ^~~~~~~~~~~~~~~
prog.c:44:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", s2);
  ^~~~~~~~~~~~~~~
/usr/bin/ld: /home/GKzH8v/ccsUuk7F.o: in function `bm_match':
prog.c:(.text+0xe6): undefined reference to `_print'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty