atof is not working.
double a = atof("12.345");
a gets set to 12.000
I am working on a toshiba micro. The data map has no space allocated
to it for dynamic memory.
Does anyone have an idea? Could it be due to the lack of dynamic
memmor space?
All thoughts gratefully received
Marky C 21 2238 eg*********@hot mail.com (Marky C) wrote: atof is not working.
double a = atof("12.345");
a gets set to 12.000
That is not allowed, surely? 12.345 must be representable, albeit
possibly with a slight error, within a double. "12.345" is a valid
string representation of 12.345. Therefore, atof() _must_ convert
"12.345" to (double)12.345 plus-or-minus a slight error, which error is
certainly smaller than two decimals.
I am working on a toshiba micro. The data map has no space allocated to it for dynamic memory.
The latter should be immaterial, but are you sure that this is a
complete hosted ISO C implementation, and not a freestanding one, or
even a non-ISO version?
Does anyone have an idea? Could it be due to the lack of dynamic memmor space?
Shouldn't be.
Richard
On 1 Apr 2004 05:29:39 -0800, eg*********@hot mail.com (Marky C) wrote: atof is not working.
double a = atof("12.345");
a gets set to 12.000
I am working on a toshiba micro. The data map has no space allocated to it for dynamic memory.
Does anyone have an idea? Could it be due to the lack of dynamic memmor space?
That's difficult to imagine. Are you sure you've included the appropriate
header file (math.h or stdlib.h)? If you'd have gotten 0 or some totally
random number instead of 12 into a, then forgetting to include the header
would have been a lot higher on my probability chart. But it is still a
possibility.
If that doesn't fix it, you may need to locate a group that knows more
specifics about your platform.
-leor All thoughts gratefully received
Marky C
--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at: www.bdsoft.com/tools/stlfilt.html
"Marky C" <eg*********@ho tmail.com> wrote in message
news:9e******** *************** ***@posting.goo gle.com... atof is not working.
double a = atof("12.345");
a gets set to 12.000
If you're using a pre-C99 compiler, and failed
to provide a prototype for 'atof()' (by #including
<stdlib.h>), then the compiler will assume that 'atof()'
returns type 'int'. This fact will truncate the
fractional part of the return value before assigning
it to 'a'. If using a C99 compiler without providing
the prototype, you should have received a diagnostic. I am working on a toshiba micro. The data map has no space allocated to it for dynamic memory.
That shouldn't matter, as long as you're using a conforming
hosted implemenatation . Does anyone have an idea? Could it be due to the lack of dynamic memmor space?
Perhaps, but I doubt it. All thoughts gratefully received
-Mike
In <9e************ **************@ posting.google. com> eg*********@hot mail.com (Marky C) writes: atof is not working.
double a = atof("12.345");
a gets set to 12.000
Did you consider including <stdlib.h> ?
I am working on a toshiba micro. The data map has no space allocated to it for dynamic memory.
Does anyone have an idea? Could it be due to the lack of dynamic memmor space?
Nope. Show us a complete program illustrating your problem.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
"Marky C" <eg*********@ho tmail.com> wrote in message
news:9e******** *************** ***@posting.goo gle.com... atof is not working.
double a = atof("12.345");
a gets set to 12.000
I am working on a toshiba micro. The data map has no space allocated to it for dynamic memory.
Does anyone have an idea? Could it be due to the lack of dynamic memmor space?
All thoughts gratefully received
Marky C
First I'd check what everyone else suggested
i.e. did you include stdlib.h?
If you did then I'd confirm the locale you are using has '.' as the decimal
point
try the following ( assuming printf actually displays something on your
system)
#include <locale.h>
#include <stdio.h>
void PrintLocaleDeci mal(void)
{
struct lconv *lcp = localeconv();
printf("decimal ='%s'\n",
lcp->decimal_point) ;
}
Marky C wrote: atof is not working.
double a = atof("12.345");
a gets set to 12.000
I am working on a toshiba micro. The data map has no space allocated to it for dynamic memory.
Does anyone have an idea? Could it be due to the lack of dynamic memmor space?
All thoughts gratefully received
Marky C
Did you #include <stdlib.h> ? If not, your compiler thinks the result of
the atof call is an int.
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94 (206)544-5225
"Mike Wahler" <mk******@mkwah ler.net> wrote in message If you're using a pre-C99 compiler, and failed to provide a prototype for 'atof()' (by #including <stdlib.h>), then the compiler will assume that 'atof()' returns type 'int'. This fact will truncate the fractional part of the return value before assigning it to 'a'.
That's not what normally happens. Generally the compiler interprets the
double as an integer, either grabbing bytes from the stack or reading from
the register used for integer returns, with garbage results.
Marky C wrote: atof is not working.
Maybe, but more likely your code is wrong.
double a = atof("12.345"); a gets set to 12.000
This suggest atof is returning an int, which would be the default
assumption if atof were not prototyped. This suggests that you forgot
to #include <stdlib.h>
I am working on a toshiba micro. The data map has no space allocated to it for dynamic memory. Does anyone have an idea? Could it be due to the lack of dynamic memmor space?
All that should be irrelevant. All thoughts gratefully received
Cut and paste the following _exactly_. Report your findings.
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
double a = atof("12.345");
double b = strtod("12.345" , 0);
printf("a = %g, b = %g\n", a, b);
return 0;
}
[output should be]
a = 12.345, b = 12.345
In <6c************ *************** *****@4ax.com> Leor Zolman <le**@bdsoft.co m> writes: On 1 Apr 2004 05:29:39 -0800, eg*********@hot mail.com (Marky C) wrote:
atof is not working.
double a = atof("12.345");
a gets set to 12.000
I am working on a toshiba micro. The data map has no space allocated to it for dynamic memory.
Does anyone have an idea? Could it be due to the lack of dynamic memmor space?
That's difficult to imagine. Are you sure you've included the appropriate header file (math.h or stdlib.h)? If you'd have gotten 0 or some totally
It's <stdlib.h> *only*. A <math.h> declaring atof would be broken.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Marky C |
last post by:
atof is not working.
double a = atof("12.345");
a gets set to 12.000
I am working on a toshiba micro. The data map has no space allocated
to it for dynamic memory.
Does anyone have an idea? Could it be due to the lack of dynamic
|
by: Adam Warner |
last post by:
Hi all,
Message ID <c1qo3f0tro@enews2.newsguy.com> is one of many informative
articles by Chris Torek about C. The particular message discusses aliasing
and concludes with this paragraph:
Under these strict type-aliasing rules, casting from (e.g.) "int *" to
"short *" is not only quite suspicious, it is also likely to cause
puzzling...
|
by: coder |
last post by:
Hi experts,
Is the following usage of strtod okay (p is a char pointer):
value = strtod(p, &p);
Is it possible that this would evoke undefined behaviour?
Or should I use a temporary pointer and then assign its value to p?
Thanks
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |