在C语言中,有没有一个函数,当给定两个字符串时,会返回子字符串重叠或重叠的大小?所以就像做的事情一样:
char s1[5] = {cart};
char s2[4] = {car};
int overlap;
overlap = get_overlap(s1, s2); /*or have overlap be a string if it returns the overlap*.
然后重叠将是 3。
如果没有,我如何制作一个返回重叠的 int 值的。
最佳答案
使用strstr
.来自链接的示例:
/* strstr example */
#include <stdio.h>
#include <string.h>
int main ()
{
char str[] ="This is a simple string";
char * pch;
pch = strstr (str,"simple");
strncpy (pch,"sample",6);
puts (str);
return 0;
}
输出:
This is a sample string
注意事项:
将匹配整个 子串;请注意 strstr
不会进行部分匹配。
关于c - C 中是否有查找子字符串重叠的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6025548/