Question
Use C++ The following is the function you might need: int ReadCorrectWords( string filename, string correctWords[], int size, int startIndex) { // Edge case if
Use C++
The following is the function you might need:
int ReadCorrectWords( string filename, string correctWords[], int size, int startIndex) { // Edge case if ( startIndex >= size) return -1; int count = 0; string word ; // Here are opening file for reading words ifstream fin; fin.open( filename );
// Edge case if ( fin.fail() ) { return -1; } // Read a word and put it in index start with startIndex while ( getline(fin,word) ) { // if array is full then break if ( ( startIndex + count ) == size ) break; correctWords[ startIndex + count ]= word; count++; } fin.close(); // return total words in array return ( startIndex + count ); }
int ReadMisspelledWords(string filename, string misspelledWords[][2], int rows, int startIndex){ int totalWordPairs = 0; //keeps the count of total number of word pairs ifstream f; //input filestream variable f.open(filename); //open the file "filename". if(!f) { //if file does not exist return (-1); } if(startIndex >= rows) { //if the misspelledWords array is already full. return (-1); }
string str1; // holds the misspelled word string str2; // holds the correct spelling while(getline(f, str1, '\t')) { //read from file if (startIndex == rows) break; misspelledWords[startIndex][0] = str1; //store the incorrect spelling in the first column (0th index) getline(f, str2, ' '); misspelledWords[startIndex][1] = str2; //store the correct spelling in the second column(1st index) startIndex++; //it also serves as the index into the array } f.close(); //close the file totalWordPairs = startIndex; //after reading from file, startIndex will contain the total word pairs return totalWordPairs; }
string CheckWord(string word,string correctWords[],int correctWordSize,string misspelledWords[][2],int misWordRow) { int idx=0; //convert word to lower case while (word[idx]!='\0') { char ch=word[idx]; ch =tolower(ch); word[idx] = ch; idx++; } for(int i=0;i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started