c - sscanf returns 1 when searching for float in a string starting with the character n or i -
in following code expect sscanf return 0, returns 1 , assigns 0.000000 float variable x. same behavior occurs when string begins letter i, no other letter.
void main() { int ss_return; float x; char str_to_sscanf[] = "noduh"; ss_return = sscanf( str_to_sscanf, "%f", &x ); printf( "\n\nthe word passed sscanf %s", str_to_sscanf ); printf( "\n\nwhen looking float, sscanf returned %d", ss_return ); printf( "\n\nand assigned %f x (declared float)", x ); printf( "\n\nwhy did sscanf not return zero????" ); }
the output of program is: "two weird looking characters"duh
what missing?
my guess library's state machine seeing "n" possible start of "nan" , "i" possible start of "inf" letting fall float conversion code. bails out because can't finish parsing , assigns default value.
Comments
Post a Comment