当前位置:
首页 >
自己实现strstr函数与strchr函数
发布时间:2025/1/21
38
豆豆
生活随笔
收集整理的这篇文章主要介绍了
自己实现strstr函数与strchr函数
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
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[tem++] == sub_str[j++])
{
if(sub_str[j] == '\0')
{
return &str[i];
}
}
}
return NULL;
}
char * Strchr(char to[], char Ch)
{
int i = 0;
while (to[i] != Ch && to[i] != '\0') i++;
return to[i] != '\0' ? to + i : NULL;
}
与50位技术专家面对面20年技术见证,附赠技术全景图
{
for(int i = 0; str[i] != '\0'; i++)
{
int tem = i; //tem保留主串中的起始判断下标位置
int j = 0;
while(str[tem++] == sub_str[j++])
{
if(sub_str[j] == '\0')
{
return &str[i];
}
}
}
return NULL;
}
char * Strchr(char to[], char Ch)
{
int i = 0;
while (to[i] != Ch && to[i] != '\0') i++;
return to[i] != '\0' ? to + i : NULL;
}
与50位技术专家面对面20年技术见证,附赠技术全景图
总结
以上是生活随笔为你收集整理的自己实现strstr函数与strchr函数的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 快速弄懂内存字节对齐
- 下一篇: SecureCRT如何显示颜色和高亮显示