diff options
author | Andinus <andinus@nand.sh> | 2021-08-11 15:26:15 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2021-08-11 15:26:15 +0530 |
commit | 321825828ac918bad28d0597a8616c6dc9802c3c (patch) | |
tree | 0b8e9cb1012197750eb58e972736319b2a6abac2 /c/isogram/src | |
parent | 2979ef790ac5b8f58495e0dd08cafd6a3a2e30a5 (diff) | |
download | exercism-321825828ac918bad28d0597a8616c6dc9802c3c.tar.gz |
Add solved exercises
Diffstat (limited to 'c/isogram/src')
-rw-r--r-- | c/isogram/src/isogram.c | 19 | ||||
-rw-r--r-- | c/isogram/src/isogram.h | 8 |
2 files changed, 27 insertions, 0 deletions
diff --git a/c/isogram/src/isogram.c b/c/isogram/src/isogram.c new file mode 100644 index 0000000..283363f --- /dev/null +++ b/c/isogram/src/isogram.c @@ -0,0 +1,19 @@ +#include "isogram.h" +#include <ctype.h> +#include <string.h> + +bool is_isogram(const char phrase[]) { + if (phrase == NULL) return false; + + bool seen[26] = {0}; + for (size_t idx = 0; phrase[idx] != '\0'; idx++) { + unsigned char cur = tolower((unsigned char) phrase[idx]); + if ('a' <= cur & cur <= 'z') { + size_t s_idx = cur - 'a'; + + if (seen[s_idx]) return false; + else seen[s_idx] = true; + } + } + return true; +} diff --git a/c/isogram/src/isogram.h b/c/isogram/src/isogram.h new file mode 100644 index 0000000..ae28cfa --- /dev/null +++ b/c/isogram/src/isogram.h @@ -0,0 +1,8 @@ +#ifndef ISOGRAM_H +#define ISOGRAM_H + +#include <stdbool.h> + +bool is_isogram(const char phrase[]); + +#endif |