Thread: Parameter in a function

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    9

    Parameter in a function

    The "combination" is defined as char combination[6]. When newCombination is called, I want the parameter c string (combo) to be set to the combination variable, if the entire combo string is numeric.

    I'm getting the error:
    Can't convert char[] to char[6].
    What does this mean??
    ---
    Also what do you think of my looping logic for checking to ensure the whole "combo" is numeric? Is it alright?

    Much appreciated as always =)


    Code:
    	void newCombination(char combo[])
    	{
    
    		//int intCombo = atoi(combo);
    		int count = 0;
    
    		for(int i = 0; i < 6;i++)
    		{
    			if(isdigit(combo[i]))
    			{
    				count++;
    			}
    		}
    		if(count == 5)
    		{
    			combination = combo;
    		}
    
    	}

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    pass size of array and array to the function and make for loop condition i<SIZE
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117
    Code:
    void newCombination(char combo[]) //I would use char*
            {
    
                    //int intCombo = atoi(combo);
                    int count = 0;
    
                    for(int i = 0; i < 6;i++)
    //might want use size() so u can use function for any size of array..
                    {
                            if(isdigit(combo[i])) count++;
                    }
                    if(count == 5) strcpy(combination,combo);  //cant use equal for c strings
            }
    char[] has no defined size so it might (I think) hold more then 6 char.
    thats why u cant put char[] in a char[6]..
    Luigi


    // I use Xcode 1.1 && CodeWarrior 8.3
    // When on Mac Os X 10.3.2

    // I use Microsoft Visual C++ 6.0
    // When on windows XP

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  4. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM