#include<iostream> using namespace std; int BFMatch(char* s,char* p) { int i=0; int j=0; while(i<strlen(s)) { while(s[i]==p[j]&&j<strlen(p)) { j++; i++; } if(j==strlen(p)) return i-strlen(p); i=i-j+1; } return -1; } int main() { char* s="123a"; char* p="a"; cout<<BFMatch(s,p)<<endl; getchar(); }