Additional Information (Failure to follow these "hints" will cause you to lose pionts.)
Think. This should be your first action. Before writing a single line of code, make sure you
can explain to
me or someone else what it is you are trying to do. If you can't write it in English (or your
native language), you will not be able to
write it in C.
Make sure you check the return value from fgets. If it returns NULL, then nothing was
read (so don't try
and do anything with the buffer that was passed in because it is meaningless.)
The dictionaries that you are given are sorted alphabetically. (Go figure.) This means you can
stop looking for a word when you encounter one that comes after the word you are looking
for. Failure to do this will result in loss of points.
The dictionaries contain exactly one word per line. All words end with a newline character. This
means you don't
have to "search" from the beginning of the word looking for the newline. It's the last character.
Always. There, I told you where it is.
So you don't have to search for it. Why are you still searching? It's at the end. Really. At.
Here's a hint: Immediately after reading a line/word from the dictionary, convert the newline to
a 0. Now, when you call strlen
on the string, it will give the correct count (without the newline). Where's the newline in
the string? See #4. Hey, here's more advice for you to ignore: Make a function that removes the newline
character from a string.
The dictionaries are not guaranteed to be in all lowercase or uppercase. You need to be
able to handle both.
Do yourself a favor: after you get the code working, make the words in lexicon.txt all
UPPERCASE, and see if
your program still works. (That's what I'm going to do.)
Since you are given a text file that contains lines, you should use fgets to read them
in. Don't use anything else.
Especially don't try to read in one character at a time. Read in the whole line. That's why I
showed you fgets.
I even posted code that shows you how to do it. Reading in one character at a time is just plain
wrong. Don't be wrong. Be Right™.
You may use any of the string functions that are found in string.h.
(e.g. strcmp, strcpy, strlen, etc.)
You may not include any other system header file.
Make sure you handle uppercase and lowercase correctly.
Make sure you set the values of any variables that might not be initialized.
(Hint: the lengths array that is passed to
the word_lengths function may not have been initialized. It could have garbage values
and likely will.)
Make sure to use "rt" in your mode parameter to fopen. If you don't, you are
not guaranteed to get
the correct results when I test your program (even though your way appears to work for
If you opened a file successfully, be sure to close it. (Be careful if you leave the function
through muliple return statements. Again, THINK!) Also, if fopen fails to open
the file DO NOT TRY TO CLOSE IT! (It's not opened). You will lose points if you
try to close it.
DO NOT USE MAGIC NUMBERS. Use the #defines that you are given in
spellcheck.h. Not using those
#defines will cause you to lose points, maybe a significant number due to
your failure to follow instructions.