int strStr(char* haystack, char* needle) {
int i=0,j=0;
char *ure=(char *)haystack;
char *s1 = NULL;
char *s2 = NULL;
while(*ure != '\0')
{
s1 = ure;
s2=(char *)needle;
while((* s1 != '\0')&&(* s2 != '\0')&&(* s1 == * s2))
{
j=i;
s1++;
s2++;
}
if(* s2 == '\0')
{
return j;
}
i++;
ure++;
}
return -1;
}
int strStr(char* haystack, char* needle)
{
int i=0,j=0;
char *ure=(char *)haystack;
while(*ure != '\0')
{
while((* haystack != '\0')&&(* needle != '\0')&&(* haystack == * needle))
{
j=i;
haystack++;
needle++;
}
if(* needle == '\0')
{
return j;
}
i++;
ure++;
}
return -1;
}
为什么在输入haystack="hello",needle="ll";第一份代码可以正确执行,第2份就不行,第一份代码我只是将 s1 = ure;s2=(char *)needle;多赋值而已这是为什么