jellyfish/cjellyfish/hamming.c

23 lines
360 B
C
Raw Normal View History

2010-07-13 20:15:08 +00:00
#include "jellyfish.h"
2010-07-11 03:39:24 +00:00
#include <ctype.h>
size_t hamming_distance(const char *s1, const char *s2) {
2010-07-11 03:39:24 +00:00
unsigned distance = 0;
for (; *s1 && *s2; s1++, s2++) {
if (*s1 != *s2) {
distance++;
2010-07-11 03:39:24 +00:00
}
}
for ( ; *s1; s1++) {
distance++;
}
for ( ; *s2; s2++) {
distance++;
}
return distance;
}