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”);

-=-
Tip me with Bitcoin to: 1ASA9q5VQUxPZvit8X2AP4JYzPcSDk7dFV or using ChangeTip (button below)


Leave a Reply

Your email address will not be published. Required fields are marked *