Malcolm said:
In practise strtod() followed by a cast to size_t is going to be good
enough. doubles can usually represent enough integers to index the
biggest array.
Actually, strtoumax() is a much better choice, and so is strtoull().
Your suggestion
strtod() returns a double, which is almost certainly a bad idea.
strtof() and strtold() are poor because they similarly return floating
point values (float & long double)/
strtol(), strtoll(), and strtoimax() return signed values (so may be
insufficient) since size_t is an unsigned value.
strtoul() returns an unsigned long, which may not be sufficient.
strtoull() returning an unsigned long long will almost certainly do the
jog, but to be as sure as possible use strtoumax() which returns an
uintmax_t. strtoumax() requires <inttypes.h>. If you don't have this
header or if the type uintmax_t is missing from it, or if strtoumax() is
missing, relying on strtoull() is probably sufficient.
However if you want to be really portable, you'll have to roll your own.
For damn sure if you think strtod() is the way to go.
It's not too difficult. The standard even has a special and
unenforceable requirement that digits be represented contigously from
0-9 in order to aid your task.
It's easily enforceable. If the digits o-9 do not have continuous and
increasing representations, then you don't have a C compiler.