I need to get an array size from user input. It seemed natural to me to store the input as size_t
, however looking for an appropriate strto...()
function I couldn't find any. I just used strtoull()
, since unsigned long long
is guaranteed to be at least 64 bits and I'm using C99 anyway. But I was wondering what would be the best way to get size_t
from a string - say, in ANSI C.
Edit:
To clarify, I don't want the string length! The user will input the size of a large buffer in the form of a string, for instance "109302393029"
. I need to get that number and store as size_t
. Of course I could use strtol()
or even atoi()
, but it seems like a clumsy hack (size_t
may hold larger values than int
, for instance, and I want the user to be able to input any value in the addressable space).