LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

reading negative zero from a string

The code sscanf("-0", "%d", &x) returns -2147483648 (hex 80000000) if x is an integer or long.

 

This is causing a problem in my radar test tool when I try to parse a string containing latitude/longitude coordinates in order to separate it into degrees and minutes.  For example, sscanf("-0:12.34", "%d:%f", &deg, &min) will return -2147483648 for the degrees.

 

I'm using LabWindows 2013/2015 on Windows 7/10.

0 Kudos
Message 1 of 2
(1,992 Views)

I have to note that Scan is more tolerant on the input string: Scan ("-0:12", %d[x]%d[x]" &deg, &min); returns deg = 0, min = 12.

 

But if you want to conform to standard libraries then you could  try with sscanf (msg, "%c%d:%d", sign, &deg, &min); and post-process the results elaborating on 'sign' value. Nevertheless, this approach will fail if no sign character is present at the beginning of the string; that is, if your string may or may not begin with a sign you will need to pre-process the string testing for a digit in the first position.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 2
(1,978 Views)