Question: I'm geeting a compilation error that says Program generated too much output. Output restricted to 50000 characters. Check program for any unterminated loops generating output.
I'm geeting a compilation error that says "Program generated too much output. Output restricted to 50000 characters. Check program for any unterminated loops generating output." I do not know how to fix that
#include
int main() { string userSentence; // Input string string phraseToFind; char menuOption; cout << "Enter a sample text:" << endl << endl; getline(cin, userSentence); // Print string cout << "You entered: " << userSentence << endl << endl; do { menuOption = printMenu(userSentence); cout << " "; } while (menuOption == 'Q' || 'q'); system ("pause"); return 0; }
char printMenu(string userSentence) { char letter; string phraseToFind; // Display Menu cout << "MENU" << endl; cout << "c - Number of non-whitespace characters" << endl; cout << "w - Number of words" << endl; cout << "f - Find text" << endl; cout << "r - Replace all !'s" << endl; cout << "s - Shorten spaces" << endl; cout << "q - Quit" << endl; // ask for input and display it cout << endl << "Choose an option:" << endl; cin >> letter; switch(letter) { case'q': case'Q': exit(0); case'C': case'c': cout << "Number of non-whitespace characters:" << GetNumOfNonWSCharacters(userSentence) << endl; break; case'W': case'w': cout << "Number of words: " << GetNumOfWords(userSentence); break; case'F': case'f': cin.ignore(); cout << "Enter a word or a phrase to find: "; getline(cin, phraseToFind); cout << phraseToFind << FindText(userSentence, phraseToFind); break; case'R': case'r': cin.ignore(); ReplaceExclamation(userSentence); cout << "Edited Text: " << userSentence<< endl; break; case's': case'S': ShortenSpace(userSentence); cout << "Edited Text: " << userSentence << endl; break; default: cout << "Wrong choice.. enter a new one letter" ; break; } return letter; } int GetNumOfNonWSCharacters(const string userSentence) { int i; int count=0; int length = userSentence.size(); for (i=0; i< length ; i++) { if(!isspace(userSentence[i])) count++; } return count; } int GetNumOfWords(const string userSentence) { int wordCount = 0; int i; int length = userSentence.size(); for (i=0; i < length;) { if(isspace(userSentence[i])) { while(isspace(userSentence[i])) i++; wordCount++; } else { i++; } } wordCount = wordCount + 1; return wordCount; }
void ReplaceExclamation(string& userSentence) { string replacedText = userSentence; int i; int length = userSentence.size();
for(i=0; i< length ; i++) {
if(userSentence[i] == '!') replacedText[i] = '.'; } userSentence = replacedText; }
void ShortenSpace(string& userSentence) { char *replacedText; int i; int j=0; int length = userSentence.size(); replacedText = new char[length+1];
for(i=0; i replacedText[j] = userSentence[i]; if(isspace(userSentence[i])) { while(isspace(userSentence[i])) i++; } else { i++; } } replacedText[j] = '\0'; userSentence = replacedText; } int FindText(string userSentence, string phrase) { int count = 0; if (phrase.size() == 0) return 0; for(size_t offset = userSentence.find(phrase); offset != string::npos; offset = userSentence.find(phrase, offset + phrase.size())) { ++count; } return count; } /* Type your code here. */
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
