When this program is run in C++, I get an error which is:
main.cpp: In function 'int main()':
main.cpp:37:17: error: 'exit' was not declared in this scope case 'Q': exit(0);
How can it be fix?
/* C++ Program that process input text */
#include
#include
using namespace std;
//Function prototypes
char print Menu();
int Get Num Of Non WS Characters(string);
int Get Num Of Words(string);
void Replace Exclamation(string&);
void Shorten Space(string&);
int Find Text(string, string);
//Main function
int main()
{
char option;
string text, phrase To Find;
//Reading text from user
count <>
get line(cin, text);
//Printing text
count <>
//Loop till user wants to quit
while(1)
{
//Printing menu
option = print Menu();
//Calling functions based on option selected by user
switch(option)
{
//User wants to quit
case 'q':
case 'Q': exit(0);
//Counting non-whitespace characters
case 'c':
case 'C': count <><>
break;
//Counting number of words
case 'w':
case 'W': count <><>
break;
//Counting number of occurrences phrase in given string
case 'f':
case 'F': cin .ignore(); count <>
count <><><><><>
break;
//Replacing ! with .
case 'r':
case 'R': Replace Exclamation(text); count <><>
break;
//Replacing multiple spaces with single space
case 's':
case 'S': Shorten Space(text); count <><>
break;
default: count <>
}
}
count
return 0;
}
//Function that prints menu
char print Menu()
{
char ch;
//Printing menu
count <"\n\n\t>
count <>
count <"\n\n\t>
//Reading user choice
cin >> ch;
return ch;
}
//Function that count number of non space characters
int Get Num Of Non WS Characters(const string text)
{
int cnt = 0, i;
int len = text .size();
//Looping over given text
for(i=0; i
{
//Counting spaces
if(!is space(text[i]))
cnt++;
}
return cnt;
}
//Function that count number of words in the string
int Get Num Of Words(const string text)
{
int words = 0, i;
int len = text. size();
//Looping over text
for(i=0; i
{
//Checking for space
if(is space(text[i]))
{
//Handling multiple spaces
while(is space(text[i]))
i++;
//Incrementing words
words++;
}
else
{
i++;
}
}
//Handling last word
words = words + 1;
return words;
}
//Function that replaces ! with .
void Replace Exclamation(string& text)
{
string new Text = text;
int i, len = text. size();
//Looping over string
for(i=0; i
{
//Replacing ! with .
if(text[i] == '!')
new Text[i] = '.';
}
text = new Text;
}
//Function that replaces Multiple spaces with single space
void Shorten Space(string& text)
{
char *new Text;
int i, len = text. size(), k=0;
new Text = new char[len+1];
//Looping over string
for(i=0; i
{
//Assign individual characters
new Text[k] = text[i];
//Handling multiple spaces
if(is space(text[i]))
{
//Replacing multiple spaces with single space
while(is space(text[i]))
i++;
}
else
{
i++;
}
}
new Text[k] = '\0';
text = new Text;
}
//Function that counts the occurrences of given phrase in a given text
int Find Text(string text, string phrase)
{
int count = 0;
if (phrase. size() == 0)
return 0;
//Counting number of phrase occurrences in the given string
for(size _t offset = text. find(phrase); offset != string::n pos; offset = text .find(phrase, offset + phrase. size()))
{
++count;
}
//Retuning count
return count;
}
"\n\n\t>"\n\n\t>