diff options
Diffstat (limited to 'rushs/tinyprintf/palindrome')
| -rw-r--r-- | rushs/tinyprintf/palindrome/palindrome.c | 47 | ||||
| -rw-r--r-- | rushs/tinyprintf/palindrome/palindrome.h | 6 |
2 files changed, 53 insertions, 0 deletions
diff --git a/rushs/tinyprintf/palindrome/palindrome.c b/rushs/tinyprintf/palindrome/palindrome.c new file mode 100644 index 0000000..2ecacfd --- /dev/null +++ b/rushs/tinyprintf/palindrome/palindrome.c @@ -0,0 +1,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; +} diff --git a/rushs/tinyprintf/palindrome/palindrome.h b/rushs/tinyprintf/palindrome/palindrome.h new file mode 100644 index 0000000..8595911 --- /dev/null +++ b/rushs/tinyprintf/palindrome/palindrome.h @@ -0,0 +1,6 @@ +#ifndef PALINDROME_H +#define PALINDROME_H + +int palindrome(const char *s); + +#endif /* !PALINDROME_H */ |
