Hi I'm trying to pass some values in an array into a single variable in C.
For example:
a[0] = 1;
a[1] = 2;
a[2] = 3;
And I want to combine it to make 123. Can anyone help me with teh syntax?
Hi I'm trying to pass some values in an array into a single variable in C.
For example:
a[0] = 1;
a[1] = 2;
a[2] = 3;
And I want to combine it to make 123. Can anyone help me with teh syntax?
Looks like you could use a loop and a multiplier that grows 10 times larger every iteration. Where's your attempt?
If you understand what you're doing, you're not learning anything.
Do you mean each line of the array in the order? I assume you do, it'd be using strcat.
Something like:
This would make string equal to 123.Code:/*First you need to declare a variable for the string:*/ char string; /*Now go to the code*/ strcat(string, a[0]) strcat(string, a[1]) strcat(string, a[2])
Or something like that anyway.
The second argument to strcat isn't a single character, so that wouldn't work anyway. Also, it looks like his array is integers, so you wouldn't use strcat there.
Quzah.
Hope is the first step on the road to disappointment.
Code:int sum = 0; for(i = 0; i<arrLen; i++) { sum+=sum*10+_array[i]; }