strtoul of negative number

You better use cppreference.com for documentation it seems to be much more accurate:

if the minus sign was part of the input sequence, the numeric value calculated from the sequence of digits is negated as if by unary minus in the result type, which applies unsigned integer wraparound rules.

and as mentioned there optional plus or minus sign is a valid symbol


Per the POSIX standard:

Since 0, {ULONG_MAX}, and {ULLONG_MAX} are returned on error and are also valid returns on success, an application wishing to check for error situations should set errno to 0, then call strtoul() or strtoull(), then check errno.

You need to check errno.

Tags:

C++

C

String