串的定义:
子串的定义:
串的存储结构:
串以\0结尾
线性存储结构:
1、定长顺序存储:
#define MAXLEN 255
//定长顺序存储
typedef struct{
char ch[MAXLEN];
int length;
}SString;
2、堆分配存储:
typedef struct{
char *ch;
int length;
}
链式存储结构:
3、块链存储:
串的基本操作:
串的定位:
int Index(String S,String T,int pos){
if(pos > 0){
int n = SrtLength(S);
int m = StrLength(T);
int i = pos;
String sub = NULL;
while(i <= n-m+1){ //若子串的长为3,那匹配到倒数第二个字符就不用比较了
SubString(sub,S,i,m);
if(StrCompare(sub,T) != 0)
i ++;
else
return i;
}
}
return 0;
}