diff options
Diffstat (limited to 'ex5-4.c')
-rw-r--r-- | ex5-4.c | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -0,0 +1,23 @@ +#include <stdio.h> + +int strend(char* const s, char* const t) { + char* s_p = s; + char* t_p = t; + for (; *s_p != '\0'; s_p++); + for (; *t_p != '\0'; t_p++); + for (; !(s_p == s || t_p == t); s_p--, t_p--) { + if (*s_p != *t_p) { + return 0; + } + } + return t_p == t; +} + +int main(void) { + printf("0==%d\n", strend("foo", "bar")); + printf("1==%d\n", strend("foo", "foo")); + printf("1==%d\n", strend("xyzfoo", "foo")); + printf("0==%d\n", strend("foo", "xyzfoo")); + printf("1==%d\n", strend("foo", "")); + printf("1==%d\n", strend("", "")); +}
\ No newline at end of file |