zoukankan      html  css  js  c++  java
  • 字符串内置函数的实现

     1 char *MyStrcpy(char *des,const char *src)
     2 {
     3 assert(des != NULL && src != NULL);
     4 char *pstr = des;
     5 while((*pstr++ = *src++)!= '');
     6 return des;
     7 }
     8 
     9 char *MyStrcat(char *des,const char *src)
    10 {
    11 assert(des != NULL && src!= NULL);
    12 char *pdes = des;
    13 while(*pdes != '') ++pdes;
    14 while((*pdes++ = *src++) != '');
    15 return des;
    16 }
    17 
    18 void *MyMemcpy(void *des,const void *src,unsigned int count)
    19 {
    20 assert(des !=NULL && src != NULL && count>0);
    21 char *pdes = (char *)des;
    22 int i=0;
    23 while(i<count && *(char *)src != '')
    24 {
    25 *pdes++=*(char *)src;
    26 src=(char *)src+1;
    27 ++i;
    28 }
    29 *pdes = *(char*)src;
    30 return des;
    31 }
    32 
    33 void* MyMemmove(void *des,const void *src,unsigned int count)
    34 {
    35 assert(des != NULL && src != NULL && count >0);
    36 char *pdes = (char *)des;
    37 if(des < src || (char *)des >(char *)src + count)
    38 {
    39 int i = 0;
    40 while(i<count && *(char *)src != '')
    41 {
    42 *pdes++ = *(char *)src;
    43 src = (char *)src+1;
    44 ++i;
    45 }
    46 }
    47 else
    48 {
    49 pdes = pdes + count;
    50 src = (char *)src + count -1;
    51 *pdes-- = '';
    52 int i= count -1;
    53 while(i>=0)
    54 {
    55 *pdes--=*(char *)src;
    56 i--;
    57 src = (char *)src -1 ;
    58 }
    59 }
    60 return des;
    61 }
  • 相关阅读:
    环形二维数组
    梦断代码(三)
    梦断代码(二)
    梦断代码(一)
    CNblogs用户体验
    《软件工程》--读书笔记三
    《软件工程》--读书笔记二
    《软件工程》--读书笔记一
    找出水王
    典型用户
  • 原文地址:https://www.cnblogs.com/susidian/p/10013192.html
Copyright © 2011-2022 走看看