summaryrefslogtreecommitdiff
path: root/graphs/piscine/palindrome/palindrome.c
blob: 2ecacfd2e766b9390daf42fc307e4a77e0413477 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "palindrome.h"

#include <stddef.h>

int palindrome(const char *s)
{
    if (s == NULL)
    {
        return 0;
    }

    if (*s == '\0')
    {
        return 1;
    }

    const char *p = s;
    while (*p)
    {
        p++;
    }
    p--;

    while (p > s)
    {
        while ((*p < '0' || (*p > '9' && *p < 'A') || (*p > 'Z' && *p < 'a')
                || *p > 'z')
               && p > s)
        {
            p--;
        }
        while ((*s < '0' || (*s > '9' && *s < 'A') || (*s > 'Z' && *s < 'a')
                || *s > 'z')
               && p > s)
        {
            s++;
        }
        if (*p != *s)
        {
            return 0;
        }
        p--;
        s++;
    }

    return 1;
}