KMP算法算字串位置
#include <iostream>
using namespace std;
#include <conio.h>
/*#include <string>
#include <iomanip>
#include <fstream>*/
#define MAXSTRLEN 255
typedef unsigned char SString[MAXSTRLEN+1];
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef struct{ //顺序串定义
char s[MAXSTRLEN+1];
int length;
}HString;
int Index(SString S,SString T,int pos) //BF算法
{
int i,j;
i=pos;
j=1;
while (i<=S[0] && j<=T[0])
{
if (S[i]=T[j]) {++i; ++j; }
else{ i=i-j+2; j=1; }
if (j>T[0]) return i-T[0];
else return 0;
}
}
void get_next(SString T, int next[] ) //计算next
{
int i,j;
i=1;
next[1]=0;
j=0;
while (i<T[0])
{
if (j==0||T[i]==T[j])
{++i; ++j; next[i]=j; }
else j=next[j];
}
}
void get_nextval(SString T,int nextval[]) //计算nextval
{
int i,j;
i=1;
nextval[1]=0;
j=0;
while (i<T[0])
{
if (j==0||T[i]==T[j])
{
++i;
++j;
if (T[i]!=T[j]) nextval[i]=j;
else nextval[i]=nextval[j];
}
else j=nextval[j];
}
}
int Index_KMP(SString S, SString T, int pos, int next[]) //KMP算法
{
int i,j;
i=pos;
j=1;
while (i<=S[0]&&j<=T[0])
{
if (j==0||S[i]==T[j]) { ++i; ++j; }
else j=next[j];
}
if (j>T[0]) return i-T[0];
else return 0;
}
int creat(char S[],int &k) //串的输入
{
cout<<"请输入";
char a;
int i=1;
while((a=getch())!='\r')
{
cout<<a;
S[i]=a;
++i;
}
k=i;
S[0]=i+48;
cout<<endl;
cout<<"**************输入成功*************"<<endl;
return 1;
}
int main()
{
HString H,H1;
int i,*n1;
cout<<"*********************实验三 : 求字串位置*******************"<<endl;
cout<<"************1.创建主串************"<<endl;
cout<<"************2.创建子串************"<<endl;
cout<<"************3.计算next的值********"<<endl;
cout<<"************4.计算nextval的值*****"<<endl;
cout<<"************5.KMP算法计算字串位置*"<<endl;
int choose;
choose=-1;
while(choose!=0)
{
cout<<"请选择";
cin>>choose;
switch(choose)
{
case 1:
creat(H.s,H.length);
break;
case 2: creat(H1.s,H1.length);
break;
case 3:
n1=new int[5];
get_next(H1.s,n1);
break;
case 4: /*for(i=1;i<H1.length;i++)
{ cout<<n1[i]<<endl;
}*/
break;
}
}
return 1;
}
error C2664: 'get_next' : cannot convert parameter 1 from 'char [255]' to 'unsigned char []'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 编译产生问题 请问是什么原因