i have started writing some code in C but I m rather new to that language. I have a long long number and want to convert it to an int array. After doing some research i have created the following function:
long long* convertNumberToArray(long long* number, int* length){
*length = trunc(log10(*number))+1;
long long num_array[*length];
int i=*length-1;
while(*number!=0)
{
//when this line is added it works!
//printf("fun: modulo: %lld", *number%10);
num_array[i] = *number%10;
*number = truncl(*number/10);
i--;
}
long long* return_array = num_array;
return return_array;
}
The weird thing is that if i run it as it is, and for example give the following number 123456 i get the following output from main:
main: 1
main: 2
main: 3
main: 4
main: 5059987506418679813
main: 5473089784
when i add the commented line
printf("fun: modulo: %lld", *number%10)
the result is correct and as expected:
main: 1
main: 2
main: 3
main: 4
main: 5
main: 6
I cannot understand this behavior and why it works when the above line is inserted. Any hint or help will be appreciated.
Thanks in advance, Dina