exercism/c/hamming/hamming.c

23 lines
364 B
C
Raw Normal View History

2024-08-13 18:02:28 -04:00
#include "hamming.h"
#include <string.h>
int compute(const char *lhs, const char *rhs) {
size_t lhsLen = strlen(lhs);
size_t rhsLen = strlen(rhs);
if (lhsLen != rhsLen)
return -1;
if (lhsLen == 0 && rhsLen == 0)
return 0;
int count = 0;
for (size_t i = 0; i < lhsLen; ++i) {
if (lhs[i] != rhs[i])
count++;
}
return count;
}