#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_STRLEN 256
#define OK 1;
#define ERROR -1;
typedef struct{
char str[MAX_STRLEN];int length;
}
StringType;
typedef int Status;
typedef struct
{ char *ch;
int length;
int pos;
int i;
}HString;
char *p,*q;
Status HString_Delete(HString &S,int i){
char *p,*q;
p=&(S.ch[i-1]);
q=S.ch+S.length-1;
for(++p;p<=q;++p)
*(p-1)=*p;
--S.length;
return OK;
}
Status HString_Insert(HString &S,int i,int e){
//在顺序线性表L中第i个位置之前插入新的元素e,
//i的合法值为1<=i<=ListLength_Sq(L)+1
char *p,*q; //定义指针
q = &(S.ch[i-1]); //q为插入位置
for(p = &(S.ch[S.length-1]);p>=q;--p)
*(p+1) = *p; //插入位置及之后的元素右移
*q = e;//插入e
++S.length; //表长增加1
return OK;
}//ListInsert_Sq
int IndexString(HString &S,HString T,int pos)
//采用顺序存储方式存储主串S和模式T
//若模式T在主串S中从第pos位置开始有匹配的子串
//返回位置,否则返回-1
{char*p,*q;
int k,j;
k=pos-1;j=0;p=S.ch+pos-1;q=T.ch;
//初始匹配位置设置
//顺序存放时第pos位置的下标值为pos-1
while((k<S.length)&&(j<T.length))
{ if(*p==*q){p++;q++;k++;j++;}
else{k=k-j+1;j=0;q=T.ch;p=S.ch+k;} //重新设置匹配位置
}
if(j==T.length)
return(k-T.length); //匹配,返回位置
else return(-1); //不匹配,返回-1
}
Status Replace(HString &S,HString T,HString Sub)
{
char*p,*q;
int pos=0;
int i;
pos=IndexString(S,T,pos);
while(pos!=-1){
pos=IndexString(S,T,pos);
if(T.length=Sub.length){
for(i=0;i<Sub.length;i++)
S.ch[pos+i]=Sub.ch[i];
}
else if(T.length>Sub.length){
for(i=0;i<T.length-Sub.length;i++)
HString_Delete(S,pos+Sub.length+i);
}
else{
int differ;
for(i=0;i<T.length;i++)
S.ch[pos+i]=Sub.ch[i];
differ=Sub.length-T.length;
for(i=0;i<differ;i++)
HString_Insert(S,pos+T.length+i,Sub.ch[differ+i-1]);
}
return OK;
}
void main()
{
StringType S,T,Sub;
char a[100]="acdesaadfeda";
char b[]="a";
char c[]="??";
int len=strlen(a);
S.ch=a;
S.length=strlen(a);
T.str=b;
T.length=strlen(b);
Sub.str=c;
Sub.length=strlen(c);
printf("-----beging-----\n");
Replace(&S,T,Sub);
printf("----end-----\n");
printf("%s\n",S.ch);
}
报错问题为:[Error] a function-definition is not allowed here before '{' token
请问这是什么意思