C++程序代码-C结构串.docVIP

  • 3
  • 0
  • 约5.52千字
  • 约 6页
  • 2017-12-13 发布于河南
  • 举报
C程序代码-C结构串

#includestdio.h #includestdlib.h #includestring.h #includestr.h void IniString(String *s,const char *c)//准构造函数 { int len=strlen(c); //计算字符串长度 s-str=(char*)malloc(len+1); //给本串s分配字符串空间 if(s-str==NULL) StrError(overflow!); strcpy(s-str,c); //给本串的字符串空间赋值 s-size=len; //记录本串的串长 } void FreeString(String *s)//准析构函数 { free(s-str); //释放本串的字符串空间 } String* Copy(String *s,const String *s1)//将结构串s1赋值给本串s { if(s-size!=s1-size) { free(s-str); //释放本串的字符串空间 s-str=(char*)malloc(s1-size+1); //重新分配本串的字符串空间 if(s-str==NULL) StrError(overflow!); s-size=s1-si

文档评论(0)

1亿VIP精品文档

相关文档