开发者

sscanf for doubles

开发者 https://www.devze.com 2022-12-27 21:12 出处:网络
This is a simple problem, but I can\'t see it: char *s = \"f 8.649292\" ; double d ; sscanf( s, \"f %f\", &d ) ;

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?


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 ) ;
0

精彩评论

暂无评论...
验证码 换一张
取 消