From cabe1a14b31edce1a247c367f8e1d7265abec34e Mon Sep 17 00:00:00 2001 From: Martin Ashby Date: Tue, 7 Feb 2023 22:20:47 +0000 Subject: Chapter 5 --- ex5-4.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 ex5-4.c (limited to 'ex5-4.c') diff --git a/ex5-4.c b/ex5-4.c new file mode 100644 index 0000000..d32e965 --- /dev/null +++ b/ex5-4.c @@ -0,0 +1,23 @@ +#include + +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 -- cgit v1.2.3-ZIG