#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int judge(char* p,char find)
{
while (find)
{
if (p != find)
{
return 0;
}
p++;
find++;
}
return 1;
}
int strStr(char str, char find)
{
char p = str;
char q = find;
int count = 0;
while (*p!=’\0’)
{
if (*p == *q)
{
if (judge(p, find))
{
return count;
}
}
p++;
count++;
}
return -1;
}
int main(void)
{
char str[1024] = " “;
gets_s(str);
char find[1024] = " “;
gets_s(find);
int count=strStr(str,find);
printf(”%d\n”, count);
system(“pause”);
return 0;
}
实现strStr
最新推荐文章于 2025-01-26 17:36:40 发布
本文介绍了一个用于在主字符串中查找子字符串的算法实现。通过使用C语言,详细展示了如何定义和使用函数来判断子字符串是否存在以及其在主字符串中的位置。此算法适用于需要进行字符串匹配的场景。
868

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



