Passing to Function - Unspecified Array

Hello, I am working on a project, but have found my self stuck on one section.

I have a function called:
arrayToInteger(int digits[], int length)

which as the title suggests, it takes the integer values in each cell of the array and joins them together to make a single integer. So an array of [1|0|1] becomes the integer 101.

The problem I am facing is that i need to make the "int digits[]" become a generic term so that I can pass in any array I want. I have set it up so I pass the array called "digits[]" into the function which works great, but I can't pass an array called "descend[]" into the function when I call it the second time.

Can you guys help me with this?

So what I'm looking for is arrayToInteger(int (any array)[], int length)

Here is the code:

int arrayToInteger(int digits[], int length )
{
std::stringstream ss;
for (unsigned i = 0; i < length; ++i)
ss << digits[i];

int integer = 0;
ss << integer;
cout << integer;
return integer;
}

Thank you.
Last edited on
Huh?

1
2
3
4
5
int foo[6];
int bar[5];
//...
int n = arrayToInteger(foo, 6);
int m = arrayToInteger(bar, 5);
Last edited on
Here is the function:

int arrayToInteger(int digits[], int length )
{
std::stringstream ss;
for (unsigned i = 0; i < length; ++i)
ss << digits[i];

int integer = 0;
ss << integer;
cout << integer;
return integer;
}

I want to make it so it will accept any array not just digits[].

What you posted is basically what I want in my main function.
That function does accept any array.
Nevermind, I'm an idiot. Haha this works just fine, it was another function that was messed up.

Thank you for the quick reply
Topic archived. No new replies allowed.