I’m stuck on Stage #NY8.
I am trying to implement ?, the zero or one quantifier. Here is the relevant snippet of my code.
else if (pattern[i]=='?'){
if (i != 0) {
//Check if the optional character matches the current character
input_index--;
if (input_index < input_line.length() && ((input_line[input_index] == pattern[i - 1]))) {
// If the optional character is present, move the index forward
std::cout << "input_line " << input_line[input_index] << "\n";
std::cout << "pattern " << pattern[i-1] << "\n";
input_index++;
}else{
i++;
}
match = true;
}
} else {
std::cout << "input_line " << input_line[input_index] << "\n";
std::cout << "pattern " << pattern[i] << "\n";
match = match_char(input_line, input_index, pattern[i]);
std::cout << "match" << match << "\n";
}
I’ve added the couts to debug. It passes the first test. The logs for that test are as follows:
remote: [tester::#NY8] $ echo -n "cat" | ./your_program.sh -E "ca?t"
remote: [your_program] input_line c
remote: [your_program] pattern c
remote: [your_program] match1
remote: [your_program] input_line a
remote: [your_program] pattern a
remote: [your_program] match1
remote: [your_program] input_line a
remote: [your_program] pattern a
remote: [your_program] input_line t
remote: [your_program] pattern t
remote: [your_program] match1
remote: [tester::#NY8] ✓ Received exit code 0.
Note that match 1 means that there was a match and match 0 means that there wasn’t.
Now for the next test, this fails and I am having trouble figuring out why. The logs for that test are as follows:
remote: [tester::#NY8] $ echo -n "dog" | ./your_program.sh -E "ca?t"
remote: [your_program] input_line d
remote: [your_program] pattern c
remote: [your_program] match0
remote: [your_program] input_line o
remote: [your_program] pattern a
remote: [your_program] match0
remote: [tester::#NY8] expected exit code 1, got 0
remote: [tester::#NY8] Test failed
If anyone has any idea of what I am doing wrong or can offer some guidance, I would really appreciate it. I’ve been stuck on this stage for a few days now. I’d be happy to share any more of my code if it helps.
Thanks!