strstr函数:返回主串中子字符串的位置后的所有字符。
#include <stdio.h>
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 NULL;
}
int main()
{
char *s = "1233345hello";
char *sub = "345";
printf("%s\n", my_strstr(s, sub));
return 0;
}
strcat
(1) 函数原型
char *strcat(char *dest, const char *src);
(2) 函数说明
dest 为目的字符串指针,src 为源字符串指针。strcat() 会将参数 src 字符串复制到参数 dest 所指的字符串尾部;dest 最后的结束字符 NULL 会被覆盖掉,并在连接后的字符串的尾部再增加一个 NULL。
注意:dest 与 src 所指的内存空间不能重叠,且 dest 要有足够的空间来容纳要复制的字符串。
(3) 返回值
返回dest 字符串起始地址。
--------------------- 本文来自 aaronymhe 的优快云 博客 ,全文地址请点击:https://blog.youkuaiyun.com/yi_ming_he/article/details/74612841?utm_source=copy