FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
C++
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
July 01, 1995
Fast String Searching

(Page 1 of 12)
July 1995/Fast String Searching/Listing 1

Listing 1 Brute force string searching function

#include <stdio.h>
int bfFind(int n, char *txt, int m,
         char *pat)
{
  int i, j, k, lim;
  int nmatch = 0;
  lim = n - m + 1;
  i = 0;
  while (i<lim) {
    k = i;
    for (j=0; j<m && txt[k] == pat[j]; j++)
       k++;
    if (j == m) {
      nmatch++;
      printf("%d \n", i);
      i += m;
    }
    else
      i++;
  }
  return(nmatch);
}
/* End of File */
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 Next Page
RELATED ARTICLES
No Related Articles
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK