strtol using errno

前端 未结 4 1891
有刺的猬
有刺的猬 2021-01-16 09:21

I have the following code:

#include 
#include 
#include 

void main(void)
{
     int data;
     char * tmp;
            


        
4条回答
  •  一生所求
    2021-01-16 09:40

    You have to check tmp is not the same as "blablabla" pointer.

    If data == 0 and tmp == "blablabla", then the input data is in the incorrect format. errno needs not to be set by the implementation if the input data is not in the expected format.

    On strtol, strtoll, strtoul, and strtoull functions C says:

    (C99, 7.20.1.4p7) If the subject sequence is empty or does not have the expected form, no conversion is performed; the value of nptr is stored in the object pointed to by endptr, provided that endptr is not a null pointer.

    (C99, 7.20.1.4p9) The strtol, strtoll, strtoul, and strtoull functions return the converted value, if any. If no conversion could be performed, zero is returned.

提交回复
热议问题