uthcode / learntosolveit

The C Programming Language Companion
http://www.learntosolveit.com
Other
198 stars 1.37k forks source link

Update Ex_4.1_strindex_rightmost.c #145

Closed Oroweln closed 2 years ago

Oroweln commented 2 years ago

The && caused return value of -1 despite matching instance of pattern in line, due to && operand checking for both variables inside the nested for loop to return true. The || operand solves this by returning true value if any of two is true. mstrindex should now return the position of the rightmost occurrence of t in s, that is 11 as desired.

orsenthil commented 2 years ago

The current code is accurate.

./main
Found the right index: 7

With the changes, it will give right index: 11, which is inaccurate.