Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: sscanf beha...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 8 Topic 9814 of 9938
Post > Topic >>

Re: sscanf behaviour

by alasham.said@[EMAIL PROTECTED] Jul 21, 2008 at 11:58 PM

Hello,

Some problems that I could identify:
.. If you need to read long float, declare your variable as long float,
use 'L' (for double type), not 'l' (for int type);
.. Reason you are not seeing decimals is probably because you did not
set the precision on the output stream

Hence:

#include <iostream>
#include <iomanip>
using namespace std;

int main(int argc, char* argv[])
{
         long float f;
         const char *test = "123456.78";
         sscanf(test, "%9Lf", &f);
         cout << setprecision(9) << f << endl;
         return 0;
}

.. Lastly: sscanf is bad for your mental health. Avoid when possible.

Regards

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 8 Posts in Topic:
sscanf behaviour
kimon.simons@[EMAIL PROTE  2008-07-21 14:38:05 
Re: sscanf behaviour
Oncaphillis <oncaphill  2008-07-21 23:12:37 
Re: sscanf behaviour
alasham.said@[EMAIL PROTE  2008-07-21 23:58:14 
Re: sscanf behaviour
Alberto Ganesh Barbati &l  2008-07-22 00:11:31 
Re: sscanf behaviour
Jack Klein <jackklein@  2008-07-22 00:13:55 
Re: sscanf behaviour
puzzlecracker <ironsel  2008-07-22 15:58:14 
Re: sscanf behaviour
cbarron413@[EMAIL PROTECT  2008-07-23 06:27:34 
Re: sscanf behaviour
Oncaphillis <oncaphill  2008-07-23 06:30:24 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Aug 27 20:50:11 CDT 2008.