/* chpt4_10.cpp * Anthony Larrain * * Problem 4.10 from the text. * Write a program get a string of maximum length 255 and two characters. * The program then subtitutes the second character for all occurrences * of the first. * * For Example, if you enter .... matter t d * The program prints madder */ #include #include #include using namespace std; void converter(char *line, char first, char second); int main(int argc, char *argv[]) { const int STRLEN = 256; char line [STRLEN]; char first,second; cout << "Enter Word or Phrase" << endl; cin.getline(line,STRLEN); cout << "Enter two characters the second will replace the first" << endl; cin >> first >> second; converter(line, first, second); cout << "After Conversion" << endl << line << endl; system("PAUSE"); return EXIT_SUCCESS; } void converter(char *line, char first, char second){ const char TERMINATOR = '\0'; for(int i = 0; *(line + i) != TERMINATOR; ++i){ if ( *(line + i) == first ){ *(line + i) = second; } } return; }