My assignment is the following:
In string matching we are looking for an instance of one string (the pattern) in another (the text). We are looking for the instance, with the lowest number of faults (mismatches).
for exmaple, if the pattern is "camb" and the text is "caammbd" we compare "positions": 1. compare "camb" with "caam" which shows 2 mismatches (m with a and b with m). 2. compare "camb" with "aamm" which shows 2 mismatches (m with a and b with m). and so on....
My prgoram reads two strings from the user and tries to find the lowest number and its "position" is returned:
int misPattern(char str[], char pattern[]){
int count = 0, maxCount = 0, worstPattern = 0, i = 0, j = 0, z = 0,
patternNum = 1;
/*in order to make minimal tests, we must have each string's length*/
int testsMade = 0;
int numOfTests = (strlen(str, MAX_LEN + 1)) - (strlen(pattern, MAX_LEN + 1));
while (str[i] != '\0' && testsMade<=numOfTests){
z = i; count = 0;
while (pattern[j] != '\0'){
if (str[z] != pattern[j])
count++;
j++;
z++;
}
j = 0;
i++;
if (count > maxCount){
maxCount= count;
worstPattern = patternNum;
}
patternNum++;
testsMade++;
}
printf("%d\n", count);
return worstPattern;
}
The worstPattern should represent the position that has the least mismatches.
As you may imagine, something went wrong here. It seems, from the debugger, that my comparisons are not going well. The strings are read well, as the dubugger shows.
Thank you for your help.