01-15-2015 04:03 PM
as per article:
zone.ni.com/reference/en-XX/help/370051V-01/cvi/libref/cvistrtod/
If no conversion is possible, the function returns zero.
what if my string equals to zero (i.e., 0.0000)? how can I know if there is no error from the conversion?
01-15-2015 11:43 PM
You may check errno. If it is set to EINVAL , you know rthat there was an error. But unfortunarely the standard (http://pubs.opengroup.org/onlinepubs/009695399/functions/strtod.html) doesn't require setting errno to EINVAL for that case.
01-19-2015 09:41 AM
using this code as an example:
char *Y = "XYZ";
double MyNum;
char *MyEndPtr;
int Err_Conversion = 0;
errno = 0; //reset
MyNum = strtod (Y, &MyEndPtr);
if ( (MyNum == 0) && (strcmp(Y, MyEndPtr) == 0) && (*MyEndPtr != '\0'))
{ Err_Conversion = 1; }
when an error occurs:
01-19-2015 10:29 AM
OK, scratch my reply above. this is the more correct one:
char *Y = "XYZ";
double MyNum;
char *MyEndPtr;
int Err_Conversion = 0;
errno = 0; //reset
MyNum = strtod (Y, &MyEndPtr);
if ( (MyNum == 0) && (strcmp(Element [LineCount][i],MyEndPtr) == 0) && (*MyEndPtr != '\0') && (errno != 0))
{ Err_Conversion = 1; }
when an error occurs:
01-20-2015 06:01 AM
I just want to highlight that a test for equality on a double value is very prone to errors: I suggest to use FP_Compare () function instead. See the function help for a detailed explanation of the problems such a test can encounter and how the function manages to avoid them.