第八周 项目1 建立顺序串

本文介绍了顺序串的基础知识,包括空串与空白串的区别、串常量与串变量的概念,以及主串与子串的关系。同时,详细讨论了静态分配和动态分配两种顺序串的存储方式,强调了动态分配在运行时通过malloc和free函数进行空间管理的特点。
摘要由CSDN通过智能技术生成

以上是基础函数,下面是源文件代码:

//头文件
#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
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值