C - 从字符串转换为无符号整数

C - convert from string to unsigned int

如何将字符串转换为无符号整数?

我知道 strtoul() 从字符串转换为 unsigned long int,但我想要正常的 int 而不是 long int

我没能找到执行此操作的函数。

刚刚测试并发现 strtoul 转换为等于 UINT_MAX 的值,所以我想这可行。

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

您想使用 strtoul(),将其分配给 long unsigned int,测试结果是否在 [0..UINT_MAX] 范围内,如果是这种情况,则分配 [=11] =] 到 unsigned int.