Assignment title: C Programming


Programming in C Q Create a a stand-alone spell-checker program in C.1. Your task for this assignment is to create, in C89, a stand-alone spell-checker program. There is some pre-existing code – check.c and check.h – to help with this.

2. Program Outline Your program will deal with three input files: a text file to check (the "user file"), a dictionary file containing correct spellings, and a settings file. The words in the user

file will be spell-checked, and any resulting corrections written back to that file. Your program must do the following:

(a) Take one command-line parameter – the name of the user file to be spellchecked. (b) Read the settings file "spellrc" and store its contents in a struct. The format of the settings file is described in Section 2.1. In brief, it contains the following

information: • The name of the dictionary file; • Whether or not to auto-correct the spelling; and

• The maximum difference between a misspelled word and any suggested correction. (c) Read the dictionary file (whose name is given inside the settings file), placing each dictionary word into a linked list. The dictionary file contains words separated by line breaks. Once the whole dictionary file has been read, your program should copy the contents of the linked list to a dynamically-allocated array.

(d) Read the user file in the same fashion. For the sake of simplicity, assume that the file consists entirely of words separated by whitespace. (That is, you do not

have to make special allowances for punctuation, though you can if you wish.) (e) Invoke the pre-existing function check(), providing a callback (pointer to a function). The check() function is described in Section 2.2, and the callback function

in Section 2.3. (f) Write the user file array (whose contents may have been corrected) back to the user file. This obviously has to happen after the check() function has finished. For the sake of simplicity, you do not need to preserve the original formatting.

2.1 The settings file The settings file must be called "spellrc" (no filename extension). Each line in the file contains a name, then "=", then a value (separated by whitespace).

The allowed setting names are: dictionary, maxcorrection and autocorrect. These settings may appear in any order, and can be repeated. If a particular setting name is repeated, the value of the last (bottom-most) occurrence must take effect. For the dictionary setting, the value is the name of the dictionary file.

For maxcorrection, the value is an integer representing the maximum allowable difference between a misspelt word and any corrections to be found. (This is the "edit distance" between two words — the number of single-character changes it takes to transform one word into another.) For autocorrect, the value is either "yes" or "no", indicating whether your program should automatically apply any corrections found, or ask the user first.

This is an example of a valid settings file: maxcorrection = 2 dictionary = thedictionary.txt

autocorrect = no Your program should store these settings in a struct for later use. Note: if a setting is missing from the file, or there is an unrecognised setting name,

or the file is otherwise not in the expected format, your program must issue an error message detailing the problem. When this happens, your program must not attempt

to spell check anything.