以上是基础函数,下面是源文件代码:
//头文件
#define MaxSize 100 //最多的字符个数
typedef struct
{ char data[MaxSize]; //定义可容纳MaxSize个字符的空间
int length; //标记当前实际串长
} SqString;
void StrAssign(SqString &s,char cstr[]); //字符串常量cstr赋给串s
void StrCopy(SqString &s,SqString t); //串t复制给串s
bool StrEqual(SqString s,SqString t); //判串相等
int StrLength(SqString s); //求串长
SqString Concat(SqString s,SqString t); //串连接
SqString SubStr(SqString s,int i,int j); //求子串
SqString InsStr(SqString s1,int i,SqString s2); //串插入
SqString DelStr(SqString s,int i,int j) ; //串删去
SqString RepStr(SqString s,int i,int j,SqString t); //串替换
void DispStr(SqString s); //输出串
//源文件
#include <stdio.h>
#include <malloc.h>
#include "SqString.h"
void StrAssign(SqString &s,char cstr[]) //s为引用型参数
{ int i;
for (i=0;cstr[i]!='\0';i++)
s.data[i]=cstr[i];
s.length=i;
}
void StrCopy(SqString &s,Sq