S
sachinahuja82
Hi
I am using atoi and strtoul in my code.
I have read from MSDN that both functions return 0 if they are
unsuccessful.
i.e strtoul returns 0 if no conversion can be performed.
Now the string that I want to convert is "0x0"
The code that I am using is
char *Temp = NULL;
char sVal [10] = "0x0";
unsigned long ulReturnValue = strtoul(sVal , &Temp , 16);
Now the value that I get in ulReturnValue is equal to 0.
So how can i do error handling here?
If i use the following code for my error handling
if(ulReturnValue == 0)
printf("Error in Conversion");
Now as i am getting value of ulReturnValue as 0 .So the above code
also gets executed.
So could you please let me know why this function returns 0 when
conversion cannot be performed.
And what should I do if I have "0x0" string to convert.
The same problem arises with atoi.atoi returns 0 if input cannot be
converted.
If we have string "0" to be converted to integer.
Then we cannot do error handling in this.
Please suggest me with some solution for the above problem.
Thanks in advance.
I am using atoi and strtoul in my code.
I have read from MSDN that both functions return 0 if they are
unsuccessful.
i.e strtoul returns 0 if no conversion can be performed.
Now the string that I want to convert is "0x0"
The code that I am using is
char *Temp = NULL;
char sVal [10] = "0x0";
unsigned long ulReturnValue = strtoul(sVal , &Temp , 16);
Now the value that I get in ulReturnValue is equal to 0.
So how can i do error handling here?
If i use the following code for my error handling
if(ulReturnValue == 0)
printf("Error in Conversion");
Now as i am getting value of ulReturnValue as 0 .So the above code
also gets executed.
So could you please let me know why this function returns 0 when
conversion cannot be performed.
And what should I do if I have "0x0" string to convert.
The same problem arises with atoi.atoi returns 0 if input cannot be
converted.
If we have string "0" to be converted to integer.
Then we cannot do error handling in this.
Please suggest me with some solution for the above problem.
Thanks in advance.