How do I make sure that strtol() have returned successfully?

后端 未结 4 1177
天涯浪人
天涯浪人 2020-12-31 07:18

according documentation:

On success, the function returns the converted integral number as a long int value. If no valid conversion could be perfor

4条回答
  •  情话喂你
    2020-12-31 07:35

    You can either check the errno or pass a non-NULL value for the second argument and compare its resulting value to str, like:

    char * endptr;
    long result = strtol(str, &endptr, 10);
    if (endptr > str)
    {
        // Use result...
    }
    

提交回复
热议问题