I'm starting to work with Linux and GTK and ran in a strange problem. I am using sprintf() in my code to parse a float into a char array.
When parsing the number 1 into the string this resulted in "1.000000" but strangely after calling gtk_init() when I then do the sprintf it results in "1,000000". How does gtk_init() modify this behavior and how can I force the program to keep parsing it to "1.000000".
This is my small example program that reproduces the problem:
#include <gtk/gtk.h>
int main(int argc, char** argv)
{
char cMessage[12];
float fNumber = 1;
sprintf(cMessage, "T:%f", fNumber);
printf("%s\n", cMessage);
gtk_init(&argc, &argv);
sprintf(cMessage, "T:%f", fNumber);
printf("%s\n", cMessage);
return 0;
}
The output of this program is the following:
T:1.000000
T:1,000000
This is related to your locale/language environment. Before calling gtk_init, you LOCALE variable must be set the the default value, C. gtk_init by default, sets the locale to whatever your desktop environment is set to.
To turn this behaviour off, you can use gtk_disable_setlocale.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With