summaryrefslogtreecommitdiff
path: root/ex5-4.c
blob: d32e9658abdaf9b97814f013a8bbee54c68b9947 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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("", ""));
}