#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<string.h>
typedef struct{
char *ch;
int length;
}Str;
//获取长度
int GetStrLength(Str* str)
{
return str->length;
}
//初始化
void strInit(Str* str)
{
str->length=0;
str->ch=NULL;
}
//赋值
int strAssign(Str* str,char* ch)
{
if(str->ch)
{
free(str->ch);
str->ch=NULL;
}
int len=0;
char *c=ch;
while(*c)
{
++len;
++c;
}
if(len==0)
{
str->ch=NULL;
str->length=0;
return 1;
}
else
{
str->ch=(char *)malloc(sizeof(char)*(len+1));
if(str->ch==NULL)
return 0;
else
{
int i=0;
c=ch;
for(i=0;i<=len;++i,++c)
str->ch[i]=*c;
str->length=len;
return 1;
}
}
}
//比较
int StrCompare(Str* str1,Str* str2)
{
int i=0;
for(i;i<str1->length&&str2->length;i++)
{
if(str1->ch[i]!&
串代码
最新推荐文章于 2019-08-19 14:23:48 发布