Why is there no strtoi in stdlib.h?

后端 未结 6 2002
深忆病人
深忆病人 2020-11-27 16:34

I have grown accustomed to strtod and variants. I am wondering why there is no strtoi shipped with stdlib.h. Why is it that the integer is left out of this part

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 16:58

    This is what I have been using.

    long long_val;
    int  int_value;
    
    errno = 0;
    long_val = strtol (theString, NULL, 10);
    if (errno)
       handle_error;
    if ((long) someIntMin > long_val || long_val > (long) someIntMax)
       handle_invalid;
    int_value = (int) long_val;
    

提交回复
热议问题