我試圖編寫在某個字符串中搜索字符串的函數。 exmaple: 「qwerty」=>搜索的關鍵 「qasazqertyqwerty」 程序返回1,因爲qwerty在字符串中找到。在字符串中查找字符串
我的代碼功能是:
int normal(char *str, char *str2)
{
int temp=0;
while(*str)
{
while(*str2)
{
if(*str == *str2)
{
temp+=1;
}
else if(temp == strlen(str2))
{
printf("%d", temp/strlen(str2));
}
str2++;
str++;
}
}
return 0;
}
到底在程序(邏輯)的問題?
而我想,它不工作......這就是爲什麼你問這個問題嗎? – ALOToverflow 2011-05-17 13:58:33
這功課呢? – 2011-05-17 14:00:04
它是功課嗎?如果不是,請改用strstr。 http://linux.die.net/man/3/strstr – shinkou 2011-05-17 14:00:09