A wrong cases offered in comments: s = ababac, t = abac.
According to the logic of the original code, the pointer s
should move back by a certain position each time in the else{}
statement, but the original code overlooks it.
I rewrite it like :
if (*ptrT == *ptrS) {
ptrT++;
} else {
ptrS -= (ptrT - t);
ptrT = t;
}
ptrS++;
it works.