473,767 Members | 2,198 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sprintf localized?

I'm working on an application which generates HTML pages. This application
is distributed to clients worldwide and one of them just reported a problem
that I find very weird.

Consider the following line of code:
sprintf(buffer, _T("var ScaleW=%lf;\r\n "),1.0);

On my machine, the output of this is:
var ScaleW=1.000000 ;

On his machine, the output is:
var ScaleW=1,000000 ;

In my mind (MSDN documentation confirms this, somewhat), sprintf should
always put a dot, rather than a comma or whatever is configured in the user
regional settings. I suppose there is a subtlety I haven't grasped yet and
I'm here to ask about it.

I tried changing my regional settings to match his and I am unable to
reproduce the problem. This leads me to think it might be a bug, or related
to some other difference between my system and his. I'm using US settings
myself, while he is using French (France) by default, and French
(Switzerland) for non-Unicode applications (my application is non-Unicode).
As mentionned before, matching those on my side did not reproduce the
problem.

One detail worthy of mentionning is the fact he has the 2.0 dotnet framework
installed on his computer, while I never installed it myself. I'm reluctant
to even installing it on my side since it's my dev machine and I would not
want my future release to require dotnet 2.0 just yet (I suppose installed
vs required are two things, but anyways).

Anybody can enlighten me on this issue?

Thanks alot,

Alex.
Feb 15 '06 #1
4 1516
> In my mind (MSDN documentation confirms this, somewhat), sprintf should
always put a dot, rather than a comma or whatever is configured in the user
regional settings. I suppose there is a subtlety I haven't grasped yet and
I'm here to ask about it.


printf (and family) is locale sensitive. This is ANSI C, and this might be
reason why it is not spelled-out in MSDN.

The difference between the MS CRT (C Runtime Library) and other (mostly
UNIX/Linux) CRTs is that the MS one starts with the locales set to match the
system, while the others start with "C" locale.
This is somewhat older observation, I did not try to see if it is still the
case with VS 2005.
--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Feb 16 '06 #2
> printf (and family) is locale sensitive. This is ANSI C, and this might be
reason why it is not spelled-out in MSDN.

The difference between the MS CRT (C Runtime Library) and other (mostly
UNIX/Linux) CRTs is that the MS one starts with the locales set to match
the
system, while the others start with "C" locale.
This is somewhat older observation, I did not try to see if it is still
the
case with VS 2005.

Yeah that's what I found out reading around on the internet. The funny thing
is that I cannot reproduce the "problem" on my computer even if I match my
locale to that of the client (same exact settings in Regional settings).
Another thing to note is that our software is already used by thousand of
french clients and none of them reported problems (it's pretty obvious,
since this bug totally ruins the use of our software when numbers are
outputed with commas).

So I don't really know what the exact deal is... Why is it that 1 out of
10000+ clients reports this problem and that even when changing my locale I
cannot reproduce the problem? One thing to note is the client has the 2.0
runtime which we had not tested on prior to this incident. I installed 2.0
on my test machine, set the locale to match the client's, reinstalled the
software and I still can't reproduce the problem.

I'm a bit lost now... It makes no sense.

If anybody has any other pointers, it would really be appreciated.

Thanks,

Alex.
Feb 16 '06 #3
> One thing to note is the client has the 2.0
runtime which we had not tested on prior to this incident. I installed 2.0
on my test machine, set the locale to match the client's, reinstalled the
software and I still can't reproduce the problem.

I have .NET 2.0 and I still can't reproduce it.
Is it possible that he is running this from a thread that sets the locales
before?

And I was wrong about MS CRT (at least the 2005): the starting locale is "C",
as it should.
--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Feb 17 '06 #4
> If anybody has any other pointers, it would really be appreciated.
Just a thought: set the locale to "C" before printf and restore it after.

Will solve the problem, but will not help understanding why this happens to
begin with. I am also curious, but I am afraid without access to that system
there is not much I can tell.

--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Feb 17 '06 #5

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

Similar topics

3
42400
by: huey_jiang | last post by:
Hi All, I am trying to figure out a right syntax to convert an integer array into hex array. sprintf worked for me on doing single integer: int i, Iarray, n=15; char buf; sprintf(buf, "0x%02x", n); The above code worked. Howeve, what I am trying to do is to convert an
6
2502
by: jt | last post by:
I need to produce 1 character array from 3 others. I tried sprintf and it terminates on the first 0, null, 0x00 it sees in tmp data. All 3 args print out nice by themselves. By trying to make the character array(alerts.msg) with sprintf doesn't work for the obvious reasons in my first sentence with tmp having those control characters. Is there another way to do this? To accomplish the same thing that sprintf does but able to do having...
1
3526
by: jimjim | last post by:
Hello, I was wondering about the implications of giving as an argument to sprintf a different data type from the one specified in the format argument. This type of question along with some others are asked below: 1. #include <stdio.h> int main(){ char buffer;
2
4723
by: aap | last post by:
I have the following code #define MAX 32 struct A { char carr; int iarr; int i; }; void main() {
1
1250
by: GeorgeB | last post by:
I use HOW TO: Send Raw Data to a Printer by Using Visual Basic .NET <URL:http://support.microsoft.com/?scid=kb;EN-US;322090> to send text to a dotmatrix printer. I cannot print localized text using this method. The printer prints correctly the localized string when i am sending it from the command prompt usind the copy con to prn. Any ideas on how to print localized text with the above method?
3
2367
by: Mark Findlay | last post by:
When programming reads of the Windows Registry, do the registry keys and values need to be localized for international use? For example, do I need to convert the key name L"\\Software\\Microsoft\\Windows" into Japanese, Korean, etc., for use in those markets? Thanks experts!
1
1994
by: cold80 | last post by:
I'm trying to understand how VS 2005 and the .NET Framework 2.0 can be used for a localized application. I've read a lot of messages, posts and guides but I can find a straight answer. I would like to write a DLL library, but I think it'll contain also some forms. I'd like to add a global resx file for all the error messages and a resource file for each form. This can be done very easily with VS2005. Then I can add a resource file for each...
12
4608
by: Henryk | last post by:
Hey there, I have some problems with the following code snippet on a Virtex-4 PowerPC with a GCC based compiler char chData; sprintf(&chData, "%+05.0f", -0.038f); --I get "-000" ??? sprintf(&chData, "%+05.0f", -0.380f); --I get "-000" ??? sprintf(&chData, "%+05.0f", -3.800f); --I get "-0004" ok
15
3532
by: krister | last post by:
Hello, I'm working in a quite large system that has some limitations. One of those is that I can't use printf() to get an output on a screen. I'm forced to use a special function, let's call it PrintOnConsole(), to get the output on a console. The problem with PrintOnConsole() is that it only takes strings as input arguments. On the other hand, I'm free to use sprintf(), so I can convert everything I want to print into a string and then...
0
9571
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10009
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9838
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8835
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5279
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3929
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
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.