Expand|Select|Wrap|Line Numbers
- #include <iostream>
- using namespace std;
- int String(char[]);
- char Menu();
- void Second(char, char, char[],int);
- int main()
- {
- char Twinkle[80] = {' '};
- char select = ' ';
- char Sub_char = 'A';
- char count = 'B';
- char cont = 'Z';
- cout <<"Please enter a string: ";
- cin.getline(Twinkle, 80);
- cout <<"\n";
- do
- {
- select = Menu();
- if(select != 'A')
- {
- cout << "Invalid selection ! Please re-enter !\n";
- cin >> select;
- }
- char String_1[80] = {' '};
- char character = ' ';
- char sub = ' ';
- int i = 0;
- switch(select)
- {
- case 'A':
- case 'a':
- {
- cout << "Please enter the character to be scanned: ";
- cin >> character;
- cout << "Please enter the character to be substituted: ";
- cin >> sub;
- Second(character, sub, String_1, 80);
- while(String_1[i] != '\0')
- {
- cout << String_1[i];
- ++i;
- }
- }
- }
- while(select != 'Z');
- system("pause");
- return 0;
- }
- }
- char Menu()
- {
- cout << "Welcome to the string program ! \n";
- cout << "=============================== \n";
- cout << "A - Substitute Character \n";
- cout << "B - Count Character \n";
- cin >>select;
- return select;
- }
- void Second(char Ch, char Su, char Str_2[],int num_1)
- {
- int i = 0;
- cout << Ch;
- cout << Su;
- cout << "The updated String is: ";
- while(Str_2[i] != '\0')
- {
- if(Str_2[i] == Ch)
- {
- Str_2[i] == Su;
- }
- i++;
- }
- }