Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

GTK fprint(%e) float writted with commas instead of dots

So, I’m creating a little solar system simulation, with calculus done in C. Once the calculations are done I put them into a json file, which is read by a web page.

I have created a function to save the coordinate of the trajectory into a json file, all coordinates are double. To print the double into my json file I use fprintf with %e (yes, I want the scientific writing).

FILE *fp = NULL;
fp = fopen("file.json", "w");    
fprintf(fp, "[[%e, %e, %e],[%e, %e, %e], %d],\n", pos.x, pos.y, pos.z, speed.x, speed.y, speed.z, time);

My problems is that, when I use the function with my main.c, it writes the double with dots as I want (ex: 3.14), but when I use the function with Gtk it writes them with commas (ex: 3,14).

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried to use g_fprintf built-in fprintf function by GTK, but I have the same problem.
Any idea how to solve this ?

(If you need more info about the code or the problems, I am at your dispositions)

>Solution :

gtk alters locales settings, switch to default with setlocale just after calling gtk_init

#include <locale.h>

int main(int argc, char *argv[])
{
    gtk_init(&argc, &argv);
    setlocale(LC_NUMERIC, "C");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading