473,569 Members | 2,870 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

strtod - Dynamic Memory?

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
Nov 14 '05 #1
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
Nov 14 '05 #2
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
Nov 14 '05 #3

"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
Nov 14 '05 #4
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
Nov 14 '05 #5

"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) ;
}


Nov 14 '05 #6


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
Nov 14 '05 #7

"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.
Nov 14 '05 #8
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

Nov 14 '05 #9
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
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
380
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
9
1958
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...
18
2435
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
0
7693
marktang
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...
0
7605
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...
0
7917
Oralloy
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. ...
1
7665
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...
1
5501
isladogs
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...
0
3651
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...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2105
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
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.