【无标题】

本文展示了C语言中的四个字符串处理函数:mystrlen用于计算字符串长度,mystrcpy用于复制字符串,mystrcmp用于比较两个字符串,以及mystrcat用于连接字符串。通过main函数实例化这些功能并打印结果。
摘要由CSDN通过智能技术生成

#include <stdio.h>                      
int mystrlen(char pstr[])
{
    int count=0;
    while(pstr[count]!='\0')
    {
        count++;
    }
    return count;
}
int main(int argc, const char *argv[])
{
    char str[100]="hello";
    int x;
    x=mystrlen(str);
    printf("count=%d\n",x);
    return 0;
}

#include <stdio.h>
void mystrcpy(char dst1[],char src1[])
{
    int i=0;
    while(1)
    {                                    
        dst1[i]=src1[i];
        if(src1[i]=='\0')
            break;
        i++;
    }
}
int main(int argc, const char *argv[])
{
    char dst[100];
    char src[32]="hello";
    mystrcpy(dst,src);
    printf("dst=%s\n",dst);
    
    return 0;
}
                                         

 #include <stdio.h>
  2 int mystrcmp(char buf1[],char str1[])
  3 {
  4     int res=0;
  5     int i;
  6     for(i=0;buf1[i]!='\0'||str1[i]!='0';i++)
  7     {
  8         res=buf1[i]-str1[i];
  9         if(res!=0)
 10         {
 11             break;
 12         }
 13     }
 14     return res;
 15 }  
 16     int main(int argc, const char *argv[])
 17     {
 18     char buf[100]="helloworld";
 19     char str[10]="hellochina";
 20     int x;
 21     x=mystrcmp(buf,str);
 22     printf("x=%d\n",x);
 23         
 24         return 0;                                       
 25     }

#include <stdio.h>
  2 void mystrcat(char s10[],char s20[])
  3 {
  4     int i=0;
  5     for(i=0;s10[i]!=0;i++)
  6     {
  7     }
  8     int j=0;
  9     for( ;s20[j]!=0;i++,j++)
 10     {
 11         s10[i]=s20[j];
 12     }
 13     s10[i]='\0';
 14 }
 15 int main(int argc, const char *argv[])
 16 {                                                       
 17     char s1[100]="hello";
 18     char s2[10]="world";
 19     mystrcat(s1,s2);
 20     printf("s1=%s\n",s1);
 21 
 22     return 0;
 23 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值