Author Topic: fscanf and numbers  (Read 7048 times)

Offline os.555

  • Single posting newcomer
  • *
  • Posts: 6
fscanf and numbers
« on: May 01, 2008, 11:44:37 am »
Hi,

I somehow changed the settings in Code::Blocks (I honestly dont know how..) and now fscanf and fprintf functions represent the double numbers with comma instead with point - e.g 48695,8795 is number and fscanf reads it whole and store, but 48695.8795 is not a number and fscanf reads only the part 48695 and then place the comma after it and fill the rest with zeros. fprintf prints doubles also with commas and not with points. I dont know what I've done (I've just included gtk.h and glade. h in my main.cpp - that's all), cause in the beginning everything in this project worked just fine.
Any help?

Thanks

Offline Belgabor

  • Multiple posting newcomer
  • *
  • Posts: 91
Re: fscanf and numbers
« Reply #1 on: May 01, 2008, 05:23:11 pm »
Did you change to wxWidgets-trunk (2.9)? I had the very same problem when I did as it now sets the locale properly so all standard functions respect the local settings. If you need to always use a decimal point, either set the locale to English somewhere at the start of your program or forget using scanf/printf and use boost as I did.

Offline os.555

  • Single posting newcomer
  • *
  • Posts: 6
Re: fscanf and numbers
« Reply #2 on: May 01, 2008, 06:36:27 pm »
Did you change to wxWidgets-trunk (2.9)?

I don't know, what it is, so I suppose the answer is no.

...either set the locale to English somewhere at the start of your program...

Like where? I'm very unexperienced in these things, so I would like you to be more specific (imagine you are explaining something to complete idiot:) ).
« Last Edit: May 01, 2008, 06:58:29 pm by os.555 »

Offline Belgabor

  • Multiple posting newcomer
  • *
  • Posts: 91
Re: fscanf and numbers
« Reply #3 on: May 01, 2008, 08:49:18 pm »
well, I just use
Code
wxLocale loc(wxLANGUAGE_ENGLISH);

Do that somewhere after wxWidgets initializes and where it is alive as long as your app is. I so far only need it in a console app, so I'm not 100% sure where to put it for a GUI app, but I'd try the OnRun() handler of your wxApp class. Maybe someone else has a better suggestion.

Offline os.555

  • Single posting newcomer
  • *
  • Posts: 6
Re: fscanf and numbers
« Reply #4 on: May 01, 2008, 09:32:07 pm »
Code
wxLocale loc(wxLANGUAGE_ENGLISH);

When I use this line I get this error: "wxLocale was not declared in this scope"

In my application I use only gtk for interface, not wxWidget...

Offline Belgabor

  • Multiple posting newcomer
  • *
  • Posts: 91
Re: fscanf and numbers
« Reply #5 on: May 02, 2008, 12:54:23 am »
Ah, ok. Then I have no experience, but a quick look at my C reference showed me 'setlocale'. But I have absolutely no idea if this interferes with GTK or whether there is a supposed (other) more correct way in GTK.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: fscanf and numbers
« Reply #6 on: May 02, 2008, 07:38:20 am »
I somehow changed the settings in Code::Blocks (I honestly dont know how..) and now fscanf and fprintf functions represent the double numbers with comma instead with point [...]

Did you put something in the environment variables (for example "LC_ALL=xx.XX") in "Settings => Environment... => Environment variables" ?

Offline os.555

  • Single posting newcomer
  • *
  • Posts: 6
Re: fscanf and numbers
« Reply #7 on: May 02, 2008, 10:17:52 am »
Did you put something in the environment variables (for example "LC_ALL=xx.XX") in "Settings => Environment... => Environment variables" ?

I didn't change anything in settings or anywhere else in Code::Blocks - I just change the code in my .c files. And in Settings => Environment I don't have anything like Environment variables. I use version 8.02

Offline os.555

  • Single posting newcomer
  • *
  • Posts: 6
Re: fscanf and numbers
« Reply #8 on: May 02, 2008, 10:38:22 am »
Then I have no experience, but a quick look at my C reference showed me 'setlocale'. But I have absolutely no idea if this interferes with GTK or whether there is a supposed (other) more correct way in GTK.

Thanks a lot - it works. I just put setlocale(LC_NUMERIC,"English") to my code and now I have all number right:)