I have a file containing strings representing float
and uint64_t
values.
I know exactly which string contains float
values and which contains uint64_t
values - that is not the problem I'm facing.
Here is how I convert them to their respective data-type:
char* t, v;
uint64_t cn;
cn = strtoull(t, &v, 10);
char* tt, vv;
float cn2;
cn2 = strtof(tt, vv);
But the problem arises at the following edge-case I want to catch:
Let's say the string for the uint64_t
is "99999999999999999999999999999999999999999999999999"
This can't be represented within 8 bytes and therefore causes an overflow resulting in cn = 18446744073709551615
.
Same problem with the float cn2
.
How can catch this behavior?