I have a lot of code for this. I also have 13 errors. I have tried to correct them but some are absurd to me, for example:
"Local function definitions are illegal" Could someone point me into the right direction to correct my problems?
Thanks so much
Code:#include <iostream> #include <fstream> #include <iomanip> using namespace std; void NumLetters(char []); void NumWords(char []); void Replace(char []); int main (void) { char NameOfFile[100]; char Selection; string WordToFind, OneLine; int StartPos = 0; int FoundPos = 0; cout << "Please type the name of the file to be opened." << endl; cin.getline(NameOfFile, 100, '\n'); do { char Selection; do { cout << "Make a choice: \n1) Count frequency of letters \n2) Count frequency of words \n3") << endl; cout << " Please select one of the following functions "; cout << "\n A)Tabulate the frequency of occurrence of letters (A...Z) in a file " << endl; cout << "\n B)Count the occurrence of a specified word in a file. "; cout << "\n C)Replace a specified word by another word in a file. "; cin >> Selection; switch(toupper(Selection)) { case 'A': NumLetters(NameOfFile); break; case 'B': cout << "Please enter the word to find." << endl; cin >> WordToFind; while(StartPos < OneLine.size() && FoundPos != -1) { FoundPos = OneLine.find(WordToFind, StartPos); cout << FoundPos << endl; StartPos = FoundPos + 1; } getline(NameOfFile, OneLine, '\n'); NumWords(NameOfFile); break; case 'C': Replace(NameOfFile); break; default: cout << "Please make a valid selection" << endl; } while(Selection != A && Selection != B && Selection != C) { cout << "Want to choose another function?" << endl; cin>> Selection; } } return 0; } void NumLetters(char fileName[100]) { int SumLetters [26]; for(int index = 0; index < 26; index++) SumLetters[index] = 0; int TotalLetters = 0; ifstream NameOfFile (fileName); while (!NameOfFile.eof()) { char TheChar; TheChar = toupper(NameOfFile.get()); if(TheChar >= 'A' && TheChar <= 'Z') { SumLetters[int(TheChar) - 65]++; TotalLetters++; } } cin.get(); for(int k = 0; k < 26; k++) { cout << "For " << char(k + 65) << " or " << char(k + 97) << " : " << endl; cout << setw(20) << "TotalCount = " << SumLetters[k] << setw(20) << "Percent = " << setiosflags(ios::fixed) << endl; } } void NumWords(char fileName[100]) { ifstream NameOfFile(fileName); string CountWord; cout << "Enter the word you would like to count." << endl; cin >> CountWord; for (int k = 0; k < CountWord.size(); k++) CountWord[k] = toupper(CountWord[k]); cin.get(); int Count = 0; while(!NameOfFile.eof()) { string OneLine; getline(NameOfFile, OneLine, '\n'); int Len = OneLine.size(); for(k = 0; k < Len; k++) OneLine[k] = toupper(OneLine[k]); if (Len > 0) { for(int StartPos = 0; StartPos < Len;) { int Pos; Pos = OneLine.find(CountWord, StartPos); if (Pos >= 0) { Count++; StartPos = Pos + CountWord.size(); } else break; } } } cout << "The Word " << " ' " << CountWord << " ' " << " is found " << Count << " times." << endl; } void Replace(char fileName[100]) { ifstream NameOfFile (fileName); string WordToReplace; string ReplaceWord; char FileOut[100]; cout << "Enter the word you would like to replace." << endl; cin >> WordToReplace; cout << "What word would you like to replace: " << WordToReplace << "with?" << endl; cin >> ReplaceWord; cin.get(); cout << "Please type where you would like the new file to go." << endl; cin.getline(FileOut, 100, '\n'); ofstream Outfile(FileOut); while(!NameOfFile.eof()) { string OneLine; getline(NameOfFile, OneLine, '\n'); int Len = OneLine.size(); if(!OneLine.empty()) { for(int StartPos = 0; StartPos < OneLine.size();) { int Pos; Pos = OneLine.find(WordToReplace, StartPos); if(Pos >= 0) { OneLine = OneLine.replace(Pos, WordToReplace.size(), ReplaceWord); StartPos = Pos + ReplaceWord.size(); cout << OneLine << endl; cin.get(); } else break; } } Outfile << Line << '\n'; } cout << "The file " << FileOut << " is nice!" << endl; }



LinkBack URL
About LinkBacks


