设为首页 加入收藏

TOP

c语言String的实现(二)
2013-07-22 17:58:37 来源: 作者: 【 】 浏览:498
Tags:语言 String 实现

 

  void StrCpy(String *dest,String src){

  *dest = StrMake(StrLen(src));

  String temp = *dest;

  while(*src){

  *temp++=*src++;

  }

  *temp = 0;

  }

  void StrFree(String *str){

  free(*str);

  *str = 0;

  }

  Status StrPrint(String str){

  CHECK(str);

  puts(str);

  return TRUE;

  }

  String StrTok(String dest,String src){

  if(dest)StrCpy(&STRBUFFER,dest);

  CHECK(src&&STRBUFFER&&*STRBUFFER);

  int length = StrLen(src);

  String ch = StrChr(src, *STRBUFFER, length);

  if(*ch == *STRBUFFER){

  do{

  *STRBUFFER++='\0';

  CHECK(*STRBUFFER);

  ch = StrChr(src, *STRBUFFER, length);

  }while(*ch == *STRBUFFER);

  }

  String result = STRBUFFER;

  String temp = result;

  while(*temp) {

  ch = StrChr(src, *temp, length);

  if (*ch == *temp) {

  *temp++ = '\0';

  CHECK(*temp);

  break;

  }else{

  temp++;

  }

  }

  STRBUFFER = temp;

  return result && *result result : 0;

  }

  String StrStr(String dest,String src){

  CHECK(dest&&src&&*dest&&*src);

  do{

  String temp = src,rt = dest;

  while(*temp == *rt){

  temp++;rt++;

  }

  if(!*temp)return dest;

  CHECK(*rt);

  dest++;

  }while(*dest);

  return 0;

  }

      

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C语言复杂声明的本质与局限 下一篇处理C语言之vfprintf的段错误

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: