数据结构顺序串创建插入计算长度等的基本运算
//顺序串的基本运算
#include<stdio.h>
#define MAXSIZE 50
int StrLength(char* s) //求串长
{
int i = 0;
while (s[i] != '\0') //对串s中的字符个数进行技术知道遇见'\0'结束
i++;
return i; ///返回串s的长度
}
int StrCat(char s1[], char s2[]) //串连接
{
int i, j, len1, len2;
len1 = StrLength;
len2 = StrLength;
if (len1 + len2 > MAXSIZE - 1) //若串s1存储空间不够,则返回错误代码
return 0;
i = 0; j = 0;
while (s1[i] != '\0')
i++;
while (s2[j] != '\0')
s1[i++] = s2[j++]; //将串s2的串值复制到串s1的串尾
s1[i] = '\0';
return 1;
}
int SubStr(char* s, char t[], int i, int len) //求字串
{ //数组t返回串s中从第i个字符开始长度为len的子串(i<=i<=串长)
int j, slen;
slen = StrLength(s);
if (i<1 || i>slen || len<0 || len>slen - i + 1) //若给定参数不在范围之内,则返回错误代码
return 0;
for (j = 0; j < len; j++)
t[j] = s[i + j - 1];
t[j] = '\0'; //给字串t置结束
return 1;
}
int StrCmp(char* s1, char* s2)
{
int i = 0;
while (s1[i] == s2[i] && s1[i]