#include <stdio.h>
int find_where(char *str1, char *str2)
{
int count = 0;
while(*str1)
{
if(*str1 == *str2)
{
char *str1tmp = str1;
char *str2tmp = str2;
while(*str2tmp)
{
if(*str2tmp != *str1tmp)
break;
str1tmp++;
str2tmp++;
}
if(*str2tmp == '\0')
{
return count;
}
}
count++;
str1++;
}
if(*str1 == '\0')
return -1;
}
int main()
{
char *str1 = "12345";
char *str2 = "34";
int x = find_where(str1, str2);
printf("%d\n",x);
return 0;
}
写一个函数,从一个字符串查找另一个字符串的位置
最新推荐文章于 2022-11-03 10:11:31 发布