//---------------------------------------------------//
// Keith Katona Cs 30s December 12thth 2006 Ass3 Q3 //
// This is a censorship and replace letter program //
//You enter in the sentence and then enter whatletter//
// that you want replaced with another letter number //
// or symbol //
// This program is copyrighted by me as of 2007 //
//___________________________________________________//
//header
#include <iostream>
#include <conio.h>
#include <time.h>
using namespace std;
//prototypes
void Print_String(char phrase[80]);
void Enter_String(char phrase[80]);
void Replace(char phrase[80], char badchar, char newchar);
//main
int main(void)
{
char phrase[80]; //the phrase first entered
char badchar; //characters to be removed
int phrasepos, badcharpos, count, howmany, offset; //keeps track of the string, times the user will type in a phrase,the string offset
bool stillbad; //tells if bad word is still in phrase
char character; //The character the user chooses
char newchar; //The character that replaces badchar
char again; //Do you want to run this program again
//Ask user how many strings
cout<<"How many strings?"<<endl;
cin>>howmany;
cin.ignore();
for(count=1; count<=howmany; count++)
{Enter_String(phrase);
do
{cout<<"What character do you want replaced?"<<endl;
badchar = getche();
cout<<"Replacement?"<<endl;
newchar = getche();
Replace(phrase, badchar, newchar);
cout<<"Another replacement? (Y/N)"<<endl;
again = toupper(_getche());
}while(again =='Y');
Print_String(phrase);
}//for
return 0;
}
//This function takes in the phrase that the
//user types in as an array
// phrase-The original Phrase
void Enter_String(char phrase[80])
{cout<<"Enter the phrase to check"<<endl;
cin.getline(phrase, 80, '\n');
}
//This Function replaces the old character
//with the new one the user chooses
// phrase-The original Phrase
// badchar-The character to remove
// newchar-The character that replaces badchar
void Replace(char phrase[80], char badchar, char newchar)
{int phrasepos;
int badcharpos;
int offset;
bool stillbad;
/* Look for bad word in entire phrase */
phrasepos = 0;
while(phrasepos < strlen(phrase))
{
if(phrase[phrasepos] == badchar)
{phrase[phrasepos] = newchar;
}//if
phrasepos++;
}//while
}//end of function
//This function prints out the phrase
//after the replacements have been made
// phrase-The original Phrase
void Print_String(char phrase[80])
{/* Print our updated phrase */
cout<<" With all references to removed the phrase is now "<<endl;
cout<<phrase<<endl;
}