strtoul

How to use `strtoul` to parse string where zero may be valid?

旧时模样 提交于 2019-12-01 05:25:31
According to the documentation for strtoul , regarding its return value... This function returns the converted integral number as a long int value. If no valid conversion could be performed, a zero value is returned. What if I'm parsing a user-supplied string of "0" where, for my application, "0" may be a valid entry? In that case it seems that I have no way to determine from using strtoul if a valid conversion was performed. Is there another way to handle this? How to use strtoul to parse string where zero may be valid? Any value returned from strtoul() may be from an expected string input or

How to use `strtoul` to parse string where zero may be valid?

淺唱寂寞╮ 提交于 2019-12-01 03:50:10
问题 According to the documentation for strtoul , regarding its return value... This function returns the converted integral number as a long int value. If no valid conversion could be performed, a zero value is returned. What if I'm parsing a user-supplied string of "0" where, for my application, "0" may be a valid entry? In that case it seems that I have no way to determine from using strtoul if a valid conversion was performed. Is there another way to handle this? 回答1: How to use strtoul to