1.strchr:返回一个字符第一次出现在该字符串中的地址
函数声明:char * strchr ( const char *, int );
char* My_strchr(const char *dest, const char src)
{
assert(dest != NULL);
while (*dest != '\0')
{
if (*dest == src)
{
return (char*)dest;
}
dest++;
}
return NULL;
}
2.strrchr:返回一个字符最后一次出现在该字符串中的地址
函数声明:char * strrchr ( const char *, int );
char* My_strrchr(const char*dest, char src)
{
assert(dest);
char *start = NULL;
while (*dest != '\0')
{
if (*dest == src)
{
start = (char*)dest;
}
dest++;
}
return start;
}
3.strpbrk:返回第一个字符串中第一个出现在第二个字符串中的字符的地址
函数声明:char * strpbrk ( cons

本文介绍了C语言中四个常用的字符串查找和匹配函数:strchr用于查找字符首次出现的位置,strpbrk找到第一个字符串中出现在第二个字符串的字符,strspn计算字符串开始部分匹配的字符数,而strcspn则返回字符串中未匹配到的字符个数。这些函数在处理字符串时非常实用。
最低0.47元/天 解锁文章
1301

被折叠的 条评论
为什么被折叠?



