Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard
for(i = 0; i < strlen(buffer) + 2;i++)int search(char* buffer,const char* word)
{
unsigned int i = 0,
j = 0;
for(i = 0; i <= strlen(buffer);i++)
{
if(buffer[i] == word[j] && j != strlen(word))
j++;
else if(j == strlen(word))
return (1);
else
j = 0;
}
return (0);
}word[j] != '\0'j != strlen(word)#include <cstring>
bool search(const char* buffer, const char* word) {
return std::strstr(buffer, word)!=0;
}
Alvaro wrote:You still didn't fix the multiple calls to strlen for the same string... You could checkinstead of
- Code: Select all
word[j] != '\0'
- Code: Select all
j != strlen(word)
EDIT: And your code still thinks that the string "bababata" does not contain the substring "babata".
You could also just write this:
- Code: Select all
#include <cstring>
bool search(const char* buffer, const char* word) {
return std::strstr(buffer, word)!=0;
}
Users browsing this forum: No registered users and 1 guest