diff options
author | Martin Ashby <martin@ashbysoft.com> | 2023-02-07 22:20:47 +0000 |
---|---|---|
committer | Martin Ashby <martin@ashbysoft.com> | 2023-02-07 22:20:47 +0000 |
commit | cabe1a14b31edce1a247c367f8e1d7265abec34e (patch) | |
tree | e66fd91f6682d084ea8484b1be43bd5631dc7610 /ex5-4.c | |
parent | 7fa502ba4e60ce762ab529996c66a1a831cb789f (diff) | |
download | learn-c-cabe1a14b31edce1a247c367f8e1d7265abec34e.tar.gz learn-c-cabe1a14b31edce1a247c367f8e1d7265abec34e.tar.bz2 learn-c-cabe1a14b31edce1a247c367f8e1d7265abec34e.tar.xz learn-c-cabe1a14b31edce1a247c367f8e1d7265abec34e.zip |
Chapter 5
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 |