Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <fstream>
- #include <algorithm>
- using namespace std;
- bool find(const vector<string>& v, string word, int start, int stop){
- if (start == stop){
- if (v[start] == word)
- return true;
- else
- return false;
- }
- else if (start > stop)
- return false;
- else{
- int middle = start + ((stop - start) / 2);
- if (v[middle] == word)
- return true;
- if (v[middle] > word)
- return find(v, word, start, middle - 1);
- if (v[middle] < word)
- return find(v, word, middle + 1, stop);
- }
- }
- int main(){
- string fileName, currentWord, fileName2, testWord;
- ifstream input1, input2;
- vector<string> fileInput;
- ofstream errorFile;
- cout << "What is the name of the dictionary file? ";
- cin >> fileName;
- cout << endl;
- input1.open(fileName.c_str());
- if (input1.is_open()){
- while (input1 >> currentWord)
- fileInput.push_back(currentWord);
- }
- else
- cout << "This file does not exist." << endl;
- sort(fileInput.begin(), fileInput.end());
- cout << "What file would you like to spell check? ";
- cin >> fileName2;
- cout << endl;
- input2.open(fileName2.c_str());
- errorFile.open("errors.txt");
- while (input2 >> testWord){
- string::iterator new_end = remove_if(testWord.begin(), testWord.end(), ::ispunct);
- testWord.erase(new_end, testWord.end());
- transform(testWord.begin(), testWord.end(), testWord.begin(), tolower);
- if (find(fileInput, testWord, 0, fileInput.size() - 1) == false)
- errorFile << testWord << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement