Fix the code and output should be 21 #include #include…

Fix the code and output should be 21 #include #include… Fix the code and output should be 21  #include #include #define MAX_POSITIONS 32int findStr(const char word[], const char* str){ int i, j, found = 0, matched = 0, posn = -1; int len = strlen(word);  for (i = 0; str[i] != ” && !found; i++)  {  if (str[i] == word[0])   {   matched = 1;   for (j = 1; str[i + j] != ” && word[j] != ”; j++)    {    if (str[i + j] == word[j])     {     matched++;     }    }   if (matched = len)    {    found = 1;    posn = i;    }   }  }  return posn; }int findMatches(const char word[], const char str[], int positions[]){ int lastPosn = 0, offset = 0, numFound = 0;  do  {  offset += lastPosn;  lastPosn += findStr(word, &str[offset]);  if (lastPosn > -1)   {   positions[numFound++] = lastPosn – offset;   offset += strlen(word);   }  } while (lastPosn >= 0 && offset < strlen(word));  return numFound;  }int main(void){ char phrase[] = { "I don't live day by day." };    char findWord[] = { "day" }; int foundIn[MAX_POSITIONS] = { 0 }; int matchesFound = 0, i;  matchesFound = findMatches(findWord, phrase, foundIn); printf("%s found in positions: ", findWord); for (i = 0; i < matchesFound; i++)  {  printf("%d%s", foundIn[i], (i == (matchesFound - 1) ? "n" : ", "));  } return 0; } Computer Science Engineering & Technology C++ Programming IPC 144

Leave a Comment

Your email address will not be published. Required fields are marked *

Order your essay today and save 30% with the discount code ESSAYHELP