I tried to parse uint64_t array to an array of char (result in decimal, separated by comma).
I used memcpy, every time I get a random values. iota() function converts max uint32_t values. I tried separate uint64_t to 2 uint32_t, but I never get a right result.
uint64_t numbers[10] = { 201234567890123456,
12345678901234567890,
98765432109876543,
65432109887,
12345234512345,
217631276371261627,
12354123512453124,
2163521442531,
2341232142132321,
1233432112 };
char array[1000] = "";
Expected result:
array = "201234567890123456,12345678901234567890,98765432109876543,65432109887,12345234512345,217631276371261627,12354123512453124,2163521442531,2341232142132321,1233432112"
I tried int64ToChar from this topic, but result is:
void uint64ToChar(char a[], int64_t n) {
memcpy(a, &n, 10);
}
uint64_t number = 12345678900987654;
char output[30] = "";
uint64ToChar(output, number);
Result:
�g]T�+
Thanks for any help.
If all the data is available at compile-time, there's no obvious reason why you should use slow run-time conversion functions like s*printf. Simply do it all at pre-processor stage:
More advanced alternatives with "X macros" are possible, if you want to micro-manage comma and space placement between numbers etc.
Please note that
12345678901234567890
is too large to be a valid signed integer constant on my 64 bit system, the max is2^63 - 1
=9.22*10^18
but this number is12.34*10^18
. I have to change it to12345678901234567890ull
to get this program to compile, since the maximum number is then18.44*10^18
.