Okay first off I would like to thank you for your help on my program. I also wanted to ask another question. I read the instructions and I need to know in this program where do I need the pointer or rather how should I set it up. the function I placed is commented out on the top but here, oh yes and don't worry about the if(select) leave it as it is:
insert
Code:
#include <iostream>
using namespace std;
char Menu();
void insrt_ch(char[],int, char , char);
//int (char*[], char);
int main()
{
char Twinkle[80] = {' '};
char select = ' ';
char Sub_char = 'A';
char count = 'B';
char cont = 'Z';
do
{
cout <<"Please enter a string: ";
cin.getline(Twinkle, 80);
cout <<"\n";
cout << Menu();
if(select != 'A' || select != 'B')
{
cout << "Invalid selection! Please re-enter!\n";
cin >>select;
}
//void insrt_ch(char Twinkle, char character, char sub);
char character = ' ';
char sub = ' ';
char letter = ' ';
int i = 0;
char next = 'C';
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;
insrt_ch (Twinkle, 80, character, sub);
cout << "The Updated string is: " << Twinkle[i] <<"\n";
while(Twinkle[i] != '\0')
{
cout << Twinkle[i];
++i;
}
cout << "\nDo you want to continue: ";
cin >> next;
cout << "\n";
cin.getline(Twinkle, 80);
break;
case 'B':
case 'b':
{
cout << "Please enter the character to be scanned: "
cin >> letter;
default: cout << endl << endl;
break;
}
}
}
while(select != 'Z');
system("pause");
return 0;
}
char Menu()
{
char select = ' ';
cout << "Welcome to the string program ! \n";
cout << "=============================== \n";
cout << "A - Substitute Character \n";
cout << "B - Count Character \n";
cin>> select;
return select;
}
void insrt_ch (char Twinkle[],int num,char character, char sub)
{
int i = 0;
for(i = 0; i < num; i++)
{
if(Twinkle[i] == character)
{
Twinkle[i] = sub;
}
}
}
Here is the instructions for the third function:
Function 3: (Accept two arguments: a pointer to the beginning of the string array and a character, return an integer value)
This function will accept a character pointer and a character. It will use the pointer to scan for the specified character. When it finds the specified character, it will start counting the number of times the specified character appears. It will also place a character 1 or 2 or 3 and so on into the place of the specified character in the string. For example, if ‘i’ is the specified character, the first occurrence of ‘i’ will be replaced with 1 and the second occurrence of ‘i’ will be replaced with 2. Because the string is stored in an array of characters, you can not place integer number into the string. To convert the integer into character before placing the ‘number’ into the string, use Table A.3 on page 798 for inspiration. Return the number of times the specified character appeared in the string. In main(), if the number is zero, output a message stating the character is not found. Otherwise, display the updated string, Also state the number of times the character is found.
Again any questions let me know
also I am not quite sure how I can post up the thread with the same one I don't want to have to post a new one.