Decimal commas with scanf() / Decimalni zarezi sa scanf()

I wrote a Wavefront .obj format reader that uses fscanf(). Imagine my surprise when getting errors such as “Unknown wavefront command ‘.5438581’ in models/tube.obj”. This was first time I compiled the game under Windows with libintl code thrown in. Turns out that scanf() family of functions adapts to your locale.

That is, since Croatian locale uses comma in place of decimal point, when fscanf() encountered a decimal point it coughed and gave up.
A simple:
setlocale(LC_ALL, “C”);
restored things to normal.
Edited: 
setlocale(LC_NUMERIC, “C”);
Napisao sam čitač za Wavefront .obj format koji koristi fscanf(). Zamislite moje iznenađenje kad sam počeo dobivati greške tipa “Unknown wavefront command ‘.5438581’ in models/tube.obj”. Ovo je prvi put da kompajlirah igru pod Windowsima s ubačenim libintl kodom. Ispada da se scanf() funkcije prilagođavaju regionalnim opcijama.
Odnosno, budući da hrvatske regionalne postavke koriste decimalni zarez umjesto decimalne točke, kad je fscanf() naletio na točku, zakašljao se i odustao.
Jednostavan:
setlocale(LC_ALL, “C”);
vraća sve na normalno.
Uređeno:
setlocale(LC_NUMERIC, “C”);


via blog.vucica.net

Leave a Reply

Your email address will not be published.

 

What is 14 + 4 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)

This site uses Akismet to reduce spam. Learn how your comment data is processed.