15

This is a simple problem, but I can't see it:

  char *s = "f 8.649292" ;
  double d ;
  sscanf( s, "f %f", &d ) ;

  printf( "d is %f\n", d ) ;

Why is d not containing the double value 8.649292?

bobobobo
  • 64,917
  • 62
  • 258
  • 363

1 Answers1

23

Oh wait, nevermind. d needs to be a float.

And to make it work you could use %lf for a double

  char *s = "f 8.649292 " ;
  double d ;
  sscanf( s, "f %lf", &d ) ;

  printf( "d is %lf\n", d ) ;
bobobobo
  • 64,917
  • 62
  • 258
  • 363