Hello,
I am attempting to convert a number from an array of chars into a reconstructed number. For example if I have an array:
Code:
char array[5] = {5,4,3,2,1};
How can I convert it into
Code:
int converted = 54321;
So far I have
Code:
#include <stdio.h>
int main(int argc, char *argv[])
{
int lc_count;
int tmp;
int array_mult = 1;
int hours_array[5] = {0,1,2,3,4}; // value is 1234
int i = 4;
for(lc_count = 0; lc_count <= 5; lc_count++)
{
tmp = hours_array[i] * array_mult;
array_mult *= 10;
--i;
tmp += tmp;
}
printf("count value is: %d" ,tmp);
system("PAUSE");
return 0;
}
but the output of printf is -200000, could anyone advise on what I may be doing incorrectly here?
Thanks
Dave