Hello i am trying to make a program witch will find a sequence of chars inside char array, but my program don't work correctly need help.
https://www.upsers.mobi/
Here is my code:
#include <iostream>
int main()
{
char MyCharArray[] = "mna89ybchellomas09as9";
char Key[] = "hello";
unsigned int KeyNumb = 0;
unsigned int CorrectInRow = 0;
for(unsigned int i = 0; i < sizeof(MyCharArray); i++){
if(MyCharArray[i] == Key[KeyNumb]){ // Check if char inside MyCharArray match with first char inside Key.
CorrectInRow++; // Increment this because i want to know how many chars match in a row.
KeyNumb++; // Increment this because now i know that next time in this loop i will want to check the next char inside Key[].
if(CorrectInRow == sizeof(Key)){ // if CorrectInRow match sizeof(Key) then i know that i have a match inside MyCharArray.
std::cout << "Found: " << Key << " At: " << i << std::endl; // Print out where and what i found.
break; // Close the for loop.
}
}
else{
KeyNumb = 0; // Setting this to zero because if MyCharArray[i] did not match Key[KeyNumb] and next time i want to check the first char inside Key[].
CorrectInRow = 0; // Setting this to zero because MyCharArray[i] did not match Key[KeyNumb].
}
}
return 0;
}