Assignment 5: Spell Checker


Rate this product

Assignment 5: Spell Checker

General: You’ll write a very simple spell checker. You must produce the output
EXACTLY as specified in this document. There is some flexibility permitted in your
solution to encourage you to adopt your own ideas for an algorithm. The limits to that
flexibility are explained below. Any extra output, or output that is inconsistent with these
requirements will result in lost points.
Your Mission: Edit the file “assignment5.c”*. You must implement the function
spellCheck. You may find it useful to write several other functions as well, and you are
allowed to use functions that you have written in previous assignments.
*All needed files can be found in folder Assignment5.
There is only one stage on this project, writing the spellCheck routine. The spellCheck
function has two parameters. The first parameter (article[]) is a pointer to an array of
characters. The contents of this array are an article that you need to spell check. The end
of the article is marked with the normal 0 (marking the end of a string). The article
includes punctuation, upper and lower case words, numbers, and abbreviations. Your
function must print every word in the article that cannot be found in the dictionary. The
dictionary is the second parameter to the function (more on this later).
For this project, a word is a sequence of two or more letters with no intervening
punctuation, numbers or other non-letters. The character immediately preceding the first
letter in the word must not be a letter, or it must be the beginning of the article. The
character immediately following the last letter in the word must not be a letter, or it must
be the end of the article.
For example, if the article were, “The red firetruck went round a corner at 50mph”, There
would be eight words (the, red, firetruck, went, round, corner, at, mph).
• “truck” doesn’t count because it is embedded inside “firetruck” (the character
immediately preceding ‘t’ is a letter).
• “a” is not a word because it is not at least two letters long.
• “mph” is a word even though the character preceding the ‘m’ is not a space.
Words don’t have to be preceded by a space, just by something other than a letter (or the
start of the article, of course). These rules are intended to make finding words EASY.
Just look for a letter, that marks the beginning, and keep scanning for consecutive letters.
When you run out of letters, that marks the end.
For each word in the article, you must see if there is a matching word in the dictionary.
The dictionary is also a character string. The end of the string is marked (as always) with
a 0. The end of each word is marked with a ‘\n’. A word in the dictionary can contain
any character (other than the ‘\n’ character). That means the dictionary can contain words
like “don’t” or “can’t”. Naturally, words from the dictionary that have non-letter
characters in them (like “don’t”) will never match a word from the article. Such words
can still appear in the dictionary. All words in the dictionary are sorted in alphabetical
For this project, a word in the article matches a word in the dictionary if the characters
from the two words are the same except for the case of the letters. So “cAT” and “Cat”
match each other, while “Id” and “I’d” do not match each other. For every word in the
article, determine if there is a matching word in the dictionary. If there is a matching
word, do nothing. If there is not a matching word in the dictionary, print the word from
the article.
You can print the words in several ways, depending on how you store the words in
memory. If the word is terminated with a 0 like a regular string, then you can use printf:
printf(“%s”, word);
If your strings are not terminated with the zero, then you will need to print them one letter
at a time (using a loop). You can print a single letter in one of two ways:
printf(“%c”, letter);
When you’re debugging your program, you will want to make sure that all the characters
you have printed show up on the screen. That may sound silly, but it is a real problem.
The computer does not always put characters on the screen, even if you’ve used printf or
putchar to print them! If you want to make sure characters have been forced to the
screen, print a new line (“\n”) or use fflush(stdout).
OUTPUT REQUIREMENTS: Your function must only print the misspelled words
from the article. Each word that you print must be printed on a line by itself (i.e., you
must print a ‘\n’ after each word of output). You may print words in all lower-case, in all
upper-case or in mixed case. The case (upper/lower/mixed) that you print the word does
not need to match the case that is used in the article. Finally, you must only print words
• satisfy the definition of being a word for this project (see above)
• do not appear in the dictionary.
• print each such word exactly one time (do not print the same misspelled word
twice) [Extra Credit].
Your program must produce no output other than the misspelled words (one word per
line). Please keep in mind that we will test your program with different articles and
different dictionaries than have been provided to you. Your program should work with
any article or dictionary that satisfies the requirements listed above. Not all articles start
with a letter or end with a letter. Not all articles have at least one word. Not all
dictionaries have at least one word.
Example Output:
Article = “I am a mispeled article in a mispeled string.”
Dictionary = <American standard dictionary
Output: mispeled

Open chat
Need help?
Can we help you?