check_spelling_string(char *dict, string wordList)

Sometimes you may want to check the spelling of a whole string at once. The function above splits a string into seperate words when it encounters whitespace. char *dict is the dictionary filename, and string wordList is the string that you would like to check. This function returns an instance of class spelling .

Spelling Class

The spelling class is defined in spellcheck.h as this:

class spelling
{
	public:
	
	string badList;
	int badWords;
};

string badList

string badList contains a list of misspelled words in string wordList as specified above. Each word is separated by a space.

int badWords

int badWords contains the number of misspelled words in string wordList as specified above. Each word is separated by a space.

An Example

Here is an example that uses the above features:

#include <iostream>
#include <spellcheck.h>

using namespace std;

int main(int argc, char *argv[])
{

	
	string str = "hello goood mornin how are youu";
	spelling s = check_spelling_string("english.dict", str);

	cout << "Original string: " << str << endl;
	cout << "Misspelled words: " << s.badList << endl;
	cout << "In total: " << s.badWords << " misspelled word(s)." << endl;
	
	return 0;
}


When run, this program outputs:

Original string: hello goood mornin how are youu
Misspelled words: goood mornin youu
In total: 3 misspelled word(s).


You can find this example as test.cpp, which is included in our GIT repository and source code downloads. To compile it, run:

$ g++ -o test test.cpp -lspellcheck (32 bit)

$ g++ -m32 -o test test.cpp -lspellcheck (64 bit)



Last edited Apr 21, 2013 at 3:19 PM by iankbhb, version 3

Comments

No comments yet.