J
J
J_o_k_e_R2012-11-28 11:18:22
linux
J_o_k_e_R, 2012-11-28 11:18:22

Why does sscanf use a comma instead of a dot when using Russian locale on linux?

We have a developer who is programming in Visual Studio using C++ with QT. His programs should work under both Windows and Linux. Unfortunately it is far from Linux.
There is me, the one who collects this man his programs under Linux. I'm pretty good at it, but far from programming.
And we have the following problem:
There is initial data like
line="EXPTIME = 0.5212 / actual integration time (sec)"
coming from outside.
Under windows, the code
sscanf(line, “%*10c %le”, &expTime)
picks out a fractional number normally.
Under Linux with any Russian locale enabled (ru_RU.UTF-8, ru_RU.KOI8-R), a comma is considered as a fractional separator and therefore only the integer part is read in our case.
If I put LANG=C, then everything works fine.
How can we be and what should we do? I wish I didn't have crutches. Because by setting LANG=C before running his program, we break the Cyrillic output.
PS Let's try to do without holivars, please, so all my ears have already buzzed about how wrong this linux is and how everything in it is not the same as it works in VS.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evengard, 2012-11-28
@J_o_k_e_R

www.cplusplus.com/reference/locale/numpunct/decimal_point/ not?

R
rPman, 2012-11-28
@rPman

Be very careful when writing programs that may depend on the installed locale, I have met people who change the locale settings in windows in a very bizarre way.
Wherever such ambiguity is possible, locale parameters are forced to be written (both in windows and in linux).
In this particular case, it is better to try to avoid saving and using the textual representation of such ambiguous things as real numbers and dates ... the first request to Google for your task is to serialize a real number into an integer representation: stackoverflow.com/questions/4733147/portability-of-binary -serialization-of-double-float-type-in-c

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question