Question: In C Language. Note: Here is the recursive function so that you can copy it. unsigned int distance (const char *a, const char *b) {

In C Language.

In C Language. Note: Here is the recursive function so that you

can copy it. unsigned int distance (const char *a, const char *b)

Note: Here is the recursive function so that you can copy it.

unsigned int distance (const char *a, const char *b) { unsigned int a_len = strlen(a); unsigned int b_len =strlen(b);

/* The base case occurs when one string is empty. */ if (a_len == 0) { return b_len; }

if (b_len == 0) {

return a_len;

} /* The recursive case. Construct new strings representing the head of each string, by truncating the last char of the strings. */ char a_head[MAX_WORD_SIZE], b_head[MAX_WORD_SIZE]; strcpy (a_head, a); strcpy (b_head, b); /* Truncate string length by 1. */ a_head[a_len - 1] = '\0' ; b_head[b_len - 1] = '\0' ;

int head_dist; /* Calculate the distance between the heads. */ if (a[a_len - 1] == b[b_len - 1]) { head_dist = distance (a_head, b_head); } else { head_dist = 1 + distance (a_head, b_head); }

/* Now, calculate the distance between each string and the head of the other */ int ahead2b_dist = 1 + distance (a_head, b); int bhead2a_dist = 1 + distnace (a, b_head);

/* The Levenshtein distance is the minimum of these three quantities. MIN is a macro. You'll need to write this. */ return MIN (head_dist, MIN (ahead2b_dist, bhead2a_dist)); }

EDIT: the dictionary file is:

/usr/share/dict/cracklib-small

Don't worry about posting a sample run, the source code just needs to be set up so that it will read and use the dictionary as needed.

Write a program that can serve as a simple spell checker. Your program should read a single line of text from the user, and then look up each word in the online dictionary. If the word is in the dictionary, print it out as typed. If the word is not in the dictionary, find another word that has the smallest Levenstein distance from the incorrectly spelled word and print that out, surrounded by asterisks Here is an example of what your program should look like when it is run: % ./spellcheck this is a twst of my spell checkun prorgam this is a test* of my spel1 checkup* *program* Use the dictionary located on ice in the file /usr/share/dict/cracklib-smal In order to receive full credit, your program must meet the following specifica- tions: All functions and related declarations that create, read, or write the dic- tionary should go into their own module. Use the static keyword to restrict the scope of any declarations that should not be seen outside of the dictionary module. . Create a Makefile that automates the building of your program. It should have rules to build every module, along with rules for all, clean, and tarball. The executable must be named spellcheck. Here is a recursive function that will calculate the Levenstein distance be- tween two C-strings: / Calculate the Levenstein distance between a and b. / unsigned int distance (eonst char .a, const char .b) unsigned int a_len strlen (a); unsigned int b lenstrlen (b); /*The base case occurs when one string is empty if (a-len-0) { return b len; if (b_len 0) t return a_len

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!