封装string函数

  1 #include <stdio.h>
  2 char* mystrcpy(char *dest,const char *src)
  3 {
  4     int i=0;
  5     while(src[i]!='\0')
  6     {
  7         dest[i]=src[i];
  8         i++;
  9     }
 10     dest[i]='\0';
 11     return dest;
 12 }
 13 int mystrcmp(const char *s1,const char *s2)
 14 {
 15     int i=0,res=0;
 16     while(s1[i]!='\0'||s2[i]!='\0')
 17     {
 18         res=s1[i]-s2[i];
 19         if(res!=0)
 20         {
 21             return res;
 22             break;
 23         }else
 24         {
 25             return 0;
 26         }
 27     }
 28 }
 29 char *mystrcat(char *dest,const char *src)
 30 {
 31     int i=0,j,k;
 32     while(dest[i]!='\0')
 33     {
 34         i++;
 35     }
 36     for(k=i,j=0;src[j]!='\0';k++,j++)
 37     {                                            
 38         dest[k]=src[j];
 39     }
 40     dest[k]='\0';
 41     return dest;
 42 }
 43 int mystrlen(const char *s)
 44 {
 45     int i=0;
 46     while(s[i]!='\0')
 47     {
 48         i++;
 49     }
 50     return i;
 51 }
 52 int main(int argc, const char *argv[])
 53 {
 54     char str1[32]="hello";
 55     char str2[32]="word";
 56 //  printf("%s\n",mystrcpy(str1,str2));
 57 //  printf("%s\n",mystrcat(str1,str2));i
 58     printf("%d\n",mystrcmp(str1,str2));
 59     printf("%d\n",mystrlen(str1));
 60     return 0;
 61 }
 

  • 9
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值