I meant "of the problem", but that was not one of my worst typos!
ok, I removed "n". I have to use my_strlen - to find the length of
the string:
That's one way, but having found the length you could put it to much
more use (I posted an outline elsewhere).
<if> follows from the inner <for> loop:
for( ps = s, pt = t; *pt == *ps && *pt !='\0'; pt++, ps++ )
lets say s = "Love" and t = "ee"
then *pt == *ps will go false and hence the NULL checking in the if condition
is required otherwise it will always print 1. I am not able to find a
replacement for this.
I don't think I am wrong, but the logic is a bit hairy, so lets just
tabulate the cases:
*ps *pt *ps == *pt
0 0 0 logically impossible
0 0 1 match found
0 x 0 no match
0 x 1 logically impossible
x 0 0 no match
x 0 1 logically impossible
x y 0 impossible (loop won't have ended)
x x 1 impossible (loop won't have ended)
The last two can't occur because the loop won't have terminated.
Three other cases are not possible due to simple logic (e.g. in the
first line, if both *pt and *pt are 0 the last entry must be 1 not
0). That leaves:
*ps *pt *ps == *pt
0 0 1 match found
0 x 0 no match
x 0 0 no match
so you could just test *ps == *pt. What this means is that loop must
have ended because *pt == 0, so there is no point in test in both.
Now, I agree this not obvious, but when you start to think this way it
does become clearer. You would, absolutely, have to have a comment
saying:
if (*ps == *pt) {
/* The for loop must have ended because *pt == 0. */
return 1;
}