Search code examples
cconverterstype-conversionunsigned-integer

C - convert from string to unsigned int


How do I convert from string to unsigned int?

I know that strtoul() converts from string to unsigned long int, but I want normal int and not long int.

I haven't been able to find a function that does that.


Solution

  • but I want normal [unsigned] int and not long [unsigned] int.

    You want to use strtoul(), assign it to a long unsigned int, test the result for being in the range of [0..UINT_MAX] and if this is the case assign the long unsigned int to an unsigned int.