先上代码吧
#include <stdio.h>
#include <string.h>
int main ()
{
char test[]="jei123";
char key[]="jeid23";
int length = strlen(key);
for(int i=0;i<length;i++)
{
if(strstr(test,&key[i])!=NULL)
{
printf ("%c已找到\n",key[i]);
}
else
{
printf ("%c失踪\n",key[i]);
}
}
return 0;
}
运行结果是
讲道理j e i都应该被找到的
接下来换代码
#include <stdio.h>
#include <string.h>
int main ()
{
char test[]="jei123";
char key[]="jei123"; //更换此处代码
int length = strlen(key);
for(int i=0;i<length;i++)
{
if(strstr(test,&key[i])!=NULL)
{
printf ("%c已找到\n",key[i]);
}
else
{
printf ("%c失踪\n",key[i]);
}
}
return 0;
}
此时又能被找到,求解
strstr (str1, str2) function is used to determine whether the string str2 is a substring of str1. If so, return the first address of str2 appearing in str1
str1, str2 is two char type pointers
Change strstrt() to strchr() to get the result you want
Remove your terrible address character. Take a look & let’s