Its simple iterative procedure see code as follows (tested one)
#include <stdio.h>
#include <string.h>
int countdiffs(char* w1, char* w2, int diffs) {
char *lw, *sw;
int i, curdiffs = 0;
if ((NULL == w1) || (NULL == w2)) {
return 0;
}
if (strlen(w2) > strlen(w1)) {
lw = w2;
sw = w1;
} else {
lw = w1;
sw = w2;
}
curdiffs += strlen(lw) - strlen(sw);
if (curdiffs > diffs) {
return 0;
}
for (i=0; i<strlen(sw); i++) {
if (sw[i] != lw[i]) {
curdiffs++;
if (curdiffs > diffs) {
return 0;
}
}
}
if (curdiffs == diffs) {
return 1;
}
return 0;
}
int main() {
char *word1="QueryHome";
char *word2="MueryHome";
int diffs = 1;
int answer;
answer = countdiffs(word1, word2, diffs);
printf("Answer:%d\n", answer);
answer = countdiffs("QueryHome", "MurryHome", 1);
printf("Answer:%d\n", answer);
return 0;
}