how to write a spell checking program in c++

c1one's Avatar, Join Date: Feb 2009
Light Poster
Spell Checker
You will write a program that reads a file and performs a spell check on the file. You should specify the name of the file from the command line.
Example
SpellCheck example.txt
Your program should read in a word list to use for the spell check. You can find a word list online using google or some other search engine. A suitable word list should list a single word per line in the file. You will read this word list into some data structure. An array can be used, but you will need to calculate the size of the array before running the program. You may also want to look into an alternate data structure like a vector or list or hash table. Once you read the dictionary into memory, you will read the file to be checked, and compare each word to the dictionary to determine if the word is in the list. If the word is not in the list, you should print the word and its location in the text. You do not need to offer suggestions for the incorrect word, just identify it as misspelled.
For instance, given the following input:
I lvoe programming class. It is teh best!
You program should output
Misspelled Words
Location Word
2 lvoe
7 teh
__________________________________________________ ______________
so basically this is how far i got that i realized i was confused can some1 help me out but like keep the code as simple as possible
Code:
#include <iostream> 
#include <conio.h> 
#include <fstream> 
#include <cstring>

using namespace std; 
int main() 
{ 
Int item[5]
Int I
ifstream inFile;
inFile.open("C:\\temp\\datafile.txt");
Char str[30];
Cin.get(str,31);
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
There are two key things you need to do in this program:
(1) loop over all the words in the input
(2) determine whether or not a given word is in your input list.

So where I'd start is to create a program that does each of these separately. Write a function that loops over the input string and prints each word. Don't do anything more than that yet; make sure this works first.

Then add a new function that checks for the existence of a given word in the data file. Just write it so that the user can enter a word and that it looks through the data file and gives you a yes or no output. Call this function *instead of* the one you wrote before.

Then when you've got both of those working you can look at interfacing the two functions with each other, so that the overall program asks for a string, loops through the words, checks each one off against the list then displays the word if it isn't, or does nothing if it is. You'll also need a counter so that you can display the 2 and 7 in the example output you gave.
0
c1one's Avatar, Join Date: Feb 2009
Light Poster
Quote:
Originally Posted by xpi0t0s View Post
There are two key things you need to do in this program:
(1) loop over all the words in the input
(2) determine whether or not a given word is in your input list.

So where I'd start is to create a program that does each of these separately. Write a function that loops over the input string and prints each word. Don't do anything more than that yet; make sure this works first.

Then add a new function that checks for the existence of a given word in the data file. Just write it so that the user can enter a word and that it looks through the data file and gives you a yes or no output. Call this function *instead of* the one you wrote before.

Then when you've got both of those working you can look at interfacing the two functions with each other, so that the overall program asks for a string, loops through the words, checks each one off against the list then displays the word if it isn't, or does nothing if it is. You'll also need a counter so that you can display the 2 and 7 in the example output you gave.
the problem is that i dont know how to do it would be cool if some1 could do 1 for me.
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Where did you get the assignment from, is it in a book, or are you on a course, or something else?
0
c1one's Avatar, Join Date: Feb 2009
Light Poster
assignment
0
c1one's Avatar, Join Date: Feb 2009
Light Poster
was an assignment for a class.
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
OK, so you're not going to have been given this cold. Look through your course notes and I'm sure you'll find code examples that can be adapted to cover this. If there really is nothing then you should complain to the tutor for doing a duff job and giving you assignments for which he hasn't already given you the tools you need to solve it.
0
c1one's Avatar, Join Date: Feb 2009
Light Poster
yeah well i asked the teacher for help and he told me to read the book.. so i did and did not find anything hence i am here.. itd be helpful if someone here was so nice as to write this code for me.. thanks in advance .
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Well, programming is a skill learnt by doing, not by looking at other people's completed examples.
If I were to write this code for you then that'd get you absolutely nowhere; you wouldn't learn anything, and next time you had an assignment you'd be just as stuck and back here for someone to be "so nice as to help you fail the course", because if there's a final exam where you have no internet access then you'll have absolutely no chance.

So, no, you'll have to write this code yourself. As your tutor says, read the book, and I'm sure you'll find stuff in there that will help. I understand you want a quick fix, but that isn't how programming works. What book is it? If I have access to a copy somewhere I might be able to give you some pointers.
0
c1one's Avatar, Join Date: Feb 2009
Light Poster
ok thanks you can delete this thread now