-
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;
}
}
-
pass size of array and array to the function and make for loop condition i<SIZE
-
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]..