summaryrefslogtreecommitdiff
path: root/ex5-4.c
diff options
context:
space:
mode:
Diffstat (limited to 'ex5-4.c')
-rw-r--r--ex5-4.c23
1 files changed, 23 insertions, 0 deletions
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 <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