1 int main (void){ 2 char* A = "abcdefgee"; 3 char* B = "bcdefg"; 4 printf("match at %d ",bf(A,B)); 5 return 0; 6 } 7 8 int bf (const char* _A,const char* _B){ 9 int m,n,i,j; 10 m = strlen (_A); 11 n = strlen (_B); 12 i = 0; 13 j = 0; 14 while(i<m && j<n) 15 { 16 if(_A[i] == _B[j]) 17 { 18 printf("OK %d %d %c %c ",i,j,_A[i],_B[j]); 19 i++; 20 j++; 21 } 22 else 23 { 24 printf("OK %d %d %c %c ",i,j,_A[i],_B[j]); 25 i = i-j+1;j=0; 26 } 27 } 28 if( j>=n ) 29 return i-n; 30 else 31 return 0; 32 }