473,396 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

strtod / setlocale

Hello,

I would like to have some advices on this problem I am having. In my
code I have hardcoded a string like:

const char foo[] = "11 0.438482 ";

I was then calling strtod to transform it back to double. Unfortunately
depending on the LOCALE settings, the strtod could fail.

Browsing through some previous post, it seems atof is not affected by
the LOCALE, correct ? Do you think this would be the correct approach to
solve my problem.

Is there a list of function that are affected by LOCALE and could fail
like strtod. My guess is that sscanf would fail the same way, but I
cannot think of any other function, where the dot versus comma would
change the behavior.

Thanks for any help
Mathieu

Jul 22 '05 #1
1 2988
Mathieu Malaterre wrote:
Hello,

I would like to have some advices on this problem I am having. In my
code I have hardcoded a string like:

const char foo[] = "11 0.438482 ";

I was then calling strtod to transform it back to double. Unfortunately
depending on the LOCALE settings, the strtod could fail.
Hardcode a double instead, and write it to a string. That way you'll get
the right decimal-point characters for your users' locales. That, or
write your own string_to_double function that does what you want. It
won't be hard.
Browsing through some previous post, it seems atof is not affected by
the LOCALE, correct ?
Well, I don't know. Looking it up in the docs is probably a faster way
to find out than browsing comp.lang.c++. Hold on, let's see ... in my
reference book, locale isn't mentioned under strtod or atof, and in the
UNIX manpages (Red Hat newlib C library) for strtod and atof the decimal
point character is explicitly given as '.'. You'd have to check the C
standard and/or the documentation for your standard library
implementation to be sure.
Do you think this would be the correct approach to
solve my problem.
What is your problem?
Is there a list of function that are affected by LOCALE and could fail
like strtod.
Buy yourself a good reference book, and look it up.
My guess is that sscanf would fail the same way, but I
cannot think of any other function, where the dot versus comma would
change the behavior.


A formatted read (>>) from a C++ istream into an object of built-in
numeric type is also affected by the stream's locale.
Jul 22 '05 #2

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

Similar topics

3
by: transam | last post by:
Hi, I use Mandrake linux 10 with German setup, Hungarian Keyboard. My Python is python 2.3.3. The following program fails: --------------------------------------------------------- import...
21
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...
3
by: J Trauntvein | last post by:
I was working with a co-worker the other day to work through the process of formatting numeric values by imbueing C++ iostreams with locales. His program's initialisation code had a call to...
3
by: Schraalhans Keukenmeester | last post by:
Hi, I run Apache 1.3.33 and PHP 5.0.4 on my Suse9.2 Linux box. If I try any of the following: setlocale (LC_TIME,'nl'); setlocale (LC_TIME,'nl_NL'); //example php.net site setlocale...
0
by: Paul Lautman | last post by:
Last night I had a web site. This morning it was returning nothing. I traced it to a call to setlocale(). It appears that something has happened that means that any call to setlocale completely...
4
by: Gary Wessle | last post by:
Hi I have a vector<stringwhich holds numbers, I need to loop and printout those numbers + a value as doubles . typedef vector<string>::const_iterator vs_itr; for(vs_itr i=vect.begin();...
18
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...
7
by: Steven Woody | last post by:
Hi, I am in Linux writing a program using setlocale(3). But I found, only the first invocation of setlocale(3) can be success, any subsequent calling of this function will fail $B!J(B return...
5
by: yogeshmk | last post by:
I'm writing an application which is required to function with many languages and also compile on Linux & windows. Here's how I find the locale .. # include <stdio.h> # include <locale.h> int...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.