Thread: last function problem

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    10

    last function problem

    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.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Firstly, don't remove the variable names in the function prototypes. It hurts overall readability of the code.
    And your question is a little unabiguous. Do you have problems writing a function? Do you have problems writing the actual function header? Do you have problems calling the function? Is there something specific about the assignment you do not understand?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 10-29-2008, 06:33 AM
  2. wxWidgets link problem
    By cboard_member in forum C++ Programming
    Replies: 2
    Last Post: 02-11-2006, 02:36 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Problem with function pointers
    By vNvNation in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2004, 06:49 AM