#include <stdio.h>
#include <stdio.h>
int str_end(const char *, const char*);
void check(const char *, const char *);
int main(void)
{
check("Man is a rope stretched over an abyss.", "an abyss.");
check("Man is an man man", "an man");
return 0;
}
void check (const char *content, const char *terminal)
{
printf("'%s' ends with '%s'? %s\n", content
, terminal
, str_end
(content
, terminal
) ? "Yes" : "No"); }
int str_end(const char *s, const char *t)
{
const char *init = t; /* Hold the initial position of *t */
while (*s) {
while (*s == *t) {
if (!(*s)) {
return 1;
}
s++;
t++;
}
s++;
t = init;
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgojaW5jbHVkZSA8c3RkaW8uaD4KCmludCBzdHJfZW5kKGNvbnN0IGNoYXIgKiwgY29uc3QgY2hhciopOwp2b2lkIGNoZWNrKGNvbnN0IGNoYXIgKiwgY29uc3QgY2hhciAqKTsKCmludCBtYWluKHZvaWQpCnsKICAgIGNoZWNrKCJNYW4gaXMgYSByb3BlIHN0cmV0Y2hlZCBvdmVyIGFuIGFieXNzLiIsICJhbiBhYnlzcy4iKTsKICAgIGNoZWNrKCJNYW4gaXMgYW4gbWFuIG1hbiIsICJhbiBtYW4iKTsKCiAgICByZXR1cm4gMDsKfQoKdm9pZCBjaGVjayAoY29uc3QgY2hhciAqY29udGVudCwgY29uc3QgY2hhciAqdGVybWluYWwpCnsKCXByaW50ZigiJyVzJyBlbmRzIHdpdGggJyVzJz8gJXNcbiIsIGNvbnRlbnQsIHRlcm1pbmFsLCBzdHJfZW5kKGNvbnRlbnQsIHRlcm1pbmFsKSA/ICJZZXMiIDogIk5vIik7Cn0KCmludCBzdHJfZW5kKGNvbnN0IGNoYXIgKnMsIGNvbnN0IGNoYXIgKnQpCnsKICAgIGNvbnN0IGNoYXIgKmluaXQgPSB0OyAgICAgICAvKiBIb2xkIHRoZSBpbml0aWFsIHBvc2l0aW9uIG9mICp0ICovCgogICAgd2hpbGUgKCpzKSB7CiAgICAgICAgd2hpbGUgKCpzID09ICp0KSB7IAogICAgICAgICAgICBpZiAoISgqcykpIHsKICAgICAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHMrKzsKICAgICAgICAgICAgdCsrOwogICAgICAgIH0KICAgICAgICBzKys7CiAgICAgICAgdCA9IGluaXQ7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==