[DGD] Use of sscanf

Felix A. Croes felix at dworkin.nl
Wed May 7 17:40:08 CEST 2003


Jay Shaffstall <jshaffst at netwalk.com> wrote:

> I'm using sscanf to try to distinguish between ints and floats, and I'm not 
> sure if the results I'm seeing are a bug in sscanf, or simply an 
> undocumented feature.  Here's the code I use:
>
> if (sscanf (temp, "%d", value) != 1)
> 	if (sscanf (temp, "%f", value) != 1)
> 		error ("variable does not hold an integer or float value.  Contents are: 
> " + temp);
>
> Where temp is a string variable containing a number the user typed in and 
> value is a mixed variable.  What I'm seeing is that the use of %d in sscanf 
> will truncate a float number and return me the integer portion of it.  So:

What it actually does is scan the integer part of the string, up to but
not including the "." which does not figure in integers.  You mistakenly
assumed that sscanf would match the entire string, when it could just
match the first two characters.

Regards,
Dworkin
_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list