# Thread: Concatenate array elements more then specified range

1. ## Concatenate array elements more then specified range

Hi
I m concatenating specific range of digits that are same from an array "element" . I have problem with range.As in my case the range is col_elem[ii]=4, but it will continue reading the next element if it is the same. My code is:

Code:
```int element[8]={0,1,3,3,3,0,1,2};
col_elem[ii]=4;

for (rr=0; rr<col_elem[ii];rr++){
join_tmp[qq]=rr;
while ((element[ii]== element[ii+1]) ) {
join_tmp[qq]= concatenate(rr+1, join_tmp[qq]);
printf("%d\n",join_tmp[qq]);
rr++;
}
qq++;
}```
Code:
```//FUNCTION TO CONCATENATE INTEGER VALUES OF SAME GROUP IN A COLUMN
unsigned concatenate(unsigned x, unsigned y) {
unsigned pow = 10;
while(y >= pow)
pow *= 10;
return x * pow + y;
}```

Code:
```I want output like
0
1
33
0
1
333```
How can i fix it? Thanks

2. I think you need to post more code. For example, where are rr, ii and qq defined? We can't see them here so we can't easily run your code to try it out. How is col_elem defined? When working with arrays you need to make sure you are indexing them appropriately, and without seeing these details its hard to verify just from what you posted.

Also using `pow' as a local variable name is confusing because pow is the name of a standard function from the math library. I think it's legal the way that you wrote it, but it looks suspect. Its like trying to name a variable `printf' - you can legally do it but its a bad idea

3. element is an array of arbitrary length, but you only want to consider the first 4. So declare a variable N, and set it to 4. Now in the while, test that element[i] == element[i+Nrepeats], and also that + i Nrepeats <= N.

4. qq,ii,rr are just rendom indexes to iterate. I just post the part that i think is useful and exclude them. But it original code i declare them.
lets make int col_elem=4;