473,386 Members | 1,699 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,386 software developers and data experts.

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 1499
> 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
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,...
6
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...
1
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...
2
by: aap | last post by:
I have the following code #define MAX 32 struct A { char carr; int iarr; int i; }; void main() {
1
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...
3
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...
1
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...
12
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" ???...
15
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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,...
0
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,...
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...

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.