int my_strlen(char *string)
{
    int len = 0;
    while (*string != '\0') {
        string++;
        len++;
    }
    return len;
}

const char *my_strstr(const char *str, const char *sub_str)
{
    for(int i = 0; str[i]!= '\0'; i++)
    {
        int tem = i; //tem保留主串中的起始判断下标位置
        int j = 0;
        while(str[i++] == sub_str[j++])
        {
            if(sub_str[j] == '\0')
            {
                return &str[tem];
            }
        }
        i = tem;
    }
    
    return "";
}
 
 
char* my_strncpy(char* dest, const char* src, int len)
{
    
    char* temp=dest;
    int i=0;
    while(i++ < len  && (*temp++ = *src++)!='\0')
    {
        
    }
    if(*(temp)!='\0')     *temp='\0';
    return dest;
    
}
 
int my_strcmp(char* str1, char* str2){
   while(*str1 && *str2 && *str1==*str2)
   {
    ++str1;
     ++str2;
   }
   return *str1-*str2;
}
 

有返回值

/*----------------------------
UART 中断服务程?
-----------------------------*/
void Uart() interrupt 4 using 1
{
    if (RI)
    {
        RI = 0; //清除RI位
//        P0 = SBUF; //P0显示串口?据
//        P22 = RB8; //P2.2显示校验位
    }
    if (TI)
    {
        TI = 0; //清除TI位
        busy = 0; //清忙标志
    }
}
/*----------------------------
发送串口数据
----------------------------*/
void SendData(uchar dat)
{
    while (busy); //等待前面的数据发送完成
    ACC = dat; //获取校验位P (PSW.0)
    if (P) //根据P来设置校验位
    {
        #if (PARITYBIT == ODD_PARITY)
        TB8 = 0; //设置校验位为0
        #elif (PARITYBIT == EVEN_PARITY)
        TB8 = 1; //设置校验位为1
        #endif
    }
    else
    {
        #if (PARITYBIT == ODD_PARITY)
        TB8 = 1; //设置校验位为1
        #elif (PARITYBIT == EVEN_PARITY)
        TB8 = 0; //设置校验位为0
        #endif
    }
    busy = 1;
    SBUF = ACC; //写数据到UART数据寄存器
}
/*----------------------------
发送字符串
----------------------------*/
void SendString(char *s)
{
    while (*s)                         //检测字符串结束标志
    {
        SendData(*s++);                 //发送当前字符
    }
}

没有返回值

 

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:637538335
关注微信