设为首页 加入收藏

TOP

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

  /*

  * String.c

  *

  *  Created on: 2012-12-4

  *      Author: Administrator

  */

  #include <stdio.h>

  #include <stdlib.h>

  #define TRUE 1

  #define FALSE 0

  #define CHECK(t) do{if(!(t))return 0;}while(0)

  typedef char* String;

  typedef int Status;

  static String STRBUFFER = 0;

  int StrLen(String buf){

  String temp = buf;

  while(*temp++);

  return temp-buf-1;

  }

  String StrMake(int length){

  return (String)malloc(length+1);

  }

  String StrChr(String buf, char ch, int length){

  while(length--&&*buf++ != ch);

  return buf-1;

  }

  void StrCat(String *dest,String src){

  String temp = (String)malloc(StrLen(*dest)+StrLen(src)+1);

  String head = temp;

  String d = *dest;

  while(*d){

  *temp++ = *d++;

  }

  while(*src){

  *temp++ = *src++;

  };

  *temp = '\0';

  *dest = head;

  }

  int StrCmp(String buf1,String buf2){

  do{

  if(*buf1>*buf2)return 1;

  if(*buf1<*buf2)return -1;

  if(!*buf1)break;

  buf1++;

  buf2++;

  }while(1);

  return 0;

  }

   

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

评论

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