How to read input from user into a double-type variable

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator: Moderators

Post Reply
HeinanXP
Posts: 19
Joined: Sun Jul 11, 2010 1:12 pm

How to read input from user into a double-type variable

Post by HeinanXP » Thu Feb 24, 2011 9:23 pm

Hey,
I am trying to read input from the user and put it inside a double-type variable?

I developed a function who does the sqrt function to a number, the problem is that I can't read any double-type input from the user, only int-type.

Does anybody knows how to write such a function that will enable me to read input from the user and put it inside a double-type variable?

Thanks in advance,

bluemimmosa
Posts: 3
Joined: Fri Feb 18, 2011 5:10 am

Re: How to read input from user into a double-type variable

Post by bluemimmosa » Fri Feb 25, 2011 11:58 am

double type format specifier is %Ld that means long double..
check here;
http://www.cplusplus.com/reference/clib ... dio/scanf/

HeinanXP
Posts: 19
Joined: Sun Jul 11, 2010 1:12 pm

Re: How to read input from user into a double-type variable

Post by HeinanXP » Sat Feb 26, 2011 9:41 pm

That could be helpful if I could use Microsoft C++ libraries, but, since I can't, I am looking for a way to actually write a function that will allow me to take a string, and put inside a double variable.

halofreak1990
Posts: 92
Joined: Thu May 27, 2010 8:54 pm
Location: Netherlands

Re: How to read input from user into a double-type variable

Post by halofreak1990 » Sun Feb 27, 2011 12:08 pm

The easiest way to get what you want would be to search online for an implementation of strtod (string to double) it's somewhere in the C library.
I've heard the Microsoft C library source code is supplied with each Visual C++ compiler, so you could take a look at it.
As long as it's written in plain C or C++, it's just a matter of copy-pasting to get it to work for you.

see http://www.cplusplus.com/reference/clibrary/cstdlib/strtod/ for more information about strtod

Post Reply