CC=gcc
CFLAGS=-g -Wall -ansi -pedantic
A single program wordcheck needs to be built. Obviously, the source code may be spread over multiple files. In this stripped-down version of the assignment, wordcheck does not do any word checking at all. It only reads a word file, builds an internal data structure (a tree, described below), and then outputs the information in that data structure.
The program must process command line options (by preference implemented using getopt() as that is most elegant and least effort).:
/* 26 elements
* each corresponds to a lower-case letter
* Note how the C compiler is able to handle
* the use of struct element which is only defined later
*/
typedef struct element NodeType[26];
/* the elements */
typedef struct element
{
unsigned char is_word_end; /* this letter ends a word */
NodeType *word_endings; /* words exist with more letters */
} ElementType;
The n-th row of a NodeType structure (a node in the
tree), corresponds to the n-th lower-case letter in the alphabet
(taking into account C's numbering from 0, the n-th row will
have index n-1). The properly initialized NodeType
structure is shown in Figure 1.
|
is_word_end denotes whether there exists a word which ends here. word_endings points to another NodeType structure in case words exist with more letters. In case this is the last letter of a word, word_endings will be NULL.
|
tree structure after the words
lemon lemonshave been processed. In the first node, all is_word_end fields are False (F) as there are no words with only one letter. The only words processed upto now start with the letter `l', so the word_endings field points to a structure with information about the second letter of words starting with `l'. In the one but last node, the is_word_end field for `n' is True (`n' is the end of the word ``lemon''). As there is a word starting with ``lemon'' (``lemons''), the word_endings field is not NULL, but points to yet another NodeType structure.
|
words
add ado adds added adder adders ape
# indent (GNU C beautifier)
#
# -ts1: tab stop width = 1
# -bli0: block indent ({}) 0
# -c28: try to start code-line comments in column 28
# -cd28: try to start declaration-line comments in column 28
# -npcs: no space after function call names
# -l72: maximum non-comment-line length
# -lc72: maximum comment-line length
#
alias indent 'indent -ts1 -bli0 -c28 -cd28 -npcs -l72 -lc72'
Beware of TABs. TAB expansion (as a number of blank spaces)
on one machine may be different from TAB expansion on another. This
may result in code which looks properly indented on one platform and
chaotic on another. To avoid this: