Skip to content

Instantly share code, notes, and snippets.

@dbr
Created Nov 19, 2012
Embed
What would you like to do?
Impact of locale on sscanf
/*
$ gcc locale_test.c
$ ./a.out
Got floats: 0.10 0.20 0.30
$ LANG="de_DE" ./a.out
Got floats: 0,00 0,00 0,00
*/
#include <stdio.h>
#include <locale.h>
int main(){
// Respect LANG/LC_ALL/LC_NUMERIC env-var
setlocale (LC_NUMERIC, "");
char in[] = "0.1 0.2 0.3";
float a, b, c;
if(sscanf(in, "%f %f %f", &a, &b, &c)){
printf("Got floats: %.02f %.02f %.02f\n", a, b, c);
}
else
{
printf("sscanf failed\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment