# copy contents of array to single value?

• 12-02-2005
mapunk
copy contents of array to single value?
I have an array, lets call it buffer.

buffer[0] = 9
buffer[1] = 2
buffer[2] = 3

how would i get a variable, x, to equal 923 (not only those numbers, but the contents of the buffer, whatever they may be)
• 12-02-2005
SlyMaelstrom
Well you could start from the back of the array and as you go backwards through it summing, just create a multiple that gets 10 times bigger everytime you decrement the index.

Code:

```int x; int sum = 0; int multiple = 1; for (x = 2; x > 0; x--) {   sum += buffer[x] * multiple;   mutiple *= 10;   }```
Another way would be to use the itoa() function on each one and strcat() the values together and atoi() that value.

Either way, I'm sure there is a better way. I wouldn't be suprised if one of the wiseasses in here came in with a STL function that does just what you're asking. :p
• 12-02-2005
pianorain
Quote:

Originally Posted by SlyMaelstrom
I wouldn't be suprised if one of the wiseasses in here came in with a STL function that does just what you're asking. :p

I would be. STL and C don't mix. ;)
• 12-02-2005
mapunk
i went with the atoi...thanks for the help