summary refs log tree commit diff stats
path: root/c/isogram/src
diff options
context:
space:
mode:
Diffstat (limited to 'c/isogram/src')
-rw-r--r--c/isogram/src/isogram.c19
-rw-r--r--c/isogram/src/isogram.h8
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