#define _CRT_SECURE_NO_WARNINGS
#include "string.h"
#include "stdio.h"
/*BP算法的实现
*@auther:ck
*/
/*函数声明*/
int Index(char *Buffer, char *buffer, int pos,int Count);
int Strlen(char *Buffer);
/*main*/
void main(void) {
int index;
int count;
char Buffer[20] ="acfgyhgtuoitmn";
char buffer[6] ="tuoit";
count = Strlen(buffer);
index=Index(Buffer, buffer,2, count);
for (int i=0; i <count;i++ ) {
printf("%c",Buffer[index++]);
}
printf("\n");
system("pause");
}
/*
*@param:pos:need found position
*@return:if found return position number ,nor return 0
*/
int Index(char *Buffer, char *buffer, int pos,int Count) {
int B, b=0;
if (pos > Strlen(Buffer))return 0;
B = pos - 1;
while (Buffer[B] !='\0'){
if (Buffer[B] == buffer[b]) {
B++; b++;
}
else
{
if (b== Count){
return B-b;/*return pos*/
}
B = B - b + 1;
b = 0;
}
}
return 0;
}
/*Number of statistical character */
unsigned int Strlen(char *Buffer) {
unsigned int count=0;
for (int i = 0;Buffer[i] != '\0'; i++) {
count++;
}
return count;
}
来源:CSDN
作者:qq_44719402
链接:https://blog.csdn.net/qq_44719402/article/details/104558712