diff options
Diffstat (limited to 'c/hamming/src')
-rw-r--r-- | c/hamming/src/hamming.c | 12 | ||||
-rw-r--r-- | c/hamming/src/hamming.h | 6 |
2 files changed, 18 insertions, 0 deletions
diff --git a/c/hamming/src/hamming.c b/c/hamming/src/hamming.c new file mode 100644 index 0000000..f9651e0 --- /dev/null +++ b/c/hamming/src/hamming.c @@ -0,0 +1,12 @@ +#include <stdlib.h> +#include "hamming.h" + +size_t compute(const char *lhs, const char *rhs) { + size_t diff = 0; + for (size_t idx = 0; ; idx++) { + short res = (lhs[idx] == '\0') + (rhs[idx] == '\0'); + if (res == 1) return -1; + if (res == 2) return diff; + if (lhs[idx] != rhs[idx]) diff++; + } +} diff --git a/c/hamming/src/hamming.h b/c/hamming/src/hamming.h new file mode 100644 index 0000000..18a1911 --- /dev/null +++ b/c/hamming/src/hamming.h @@ -0,0 +1,6 @@ +#ifndef HAMMING_H +#define HAMMING_H + +size_t compute(const char *lhs, const char *rhs); + +#endif |