locale "de_DE.UTF-8", fscanf problem?

Tilman Kuepper tilman.kuepper@hm.edu
Tue Dec 17 09:35:00 GMT 2013


Hello,

There seems to be an "unbalance" with fprintf and fscanf when using the 
"de_DE.UTF-8" locale.

The following program correctly writes "2,5" (decimal comma) to a file. But 
reading with fscanf fails - the decimal comma is treated as "end of number".

Regards,
Tilman

--------------

#include <locale.h>
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    double test;
    setlocale(LC_NUMERIC, "de_DE.UTF-8");

    FILE* fp = fopen("test.txt", "w");
    fprintf(fp, "%f", 2.5);
    fclose(fp);

    printf("fprintf writes:\n");
    system("cat test.txt");

    fp = fopen("test.txt", "r");
    fscanf(fp, "%lf", &test);
    fclose(fp);

    printf("\nfscanf reads:\n%f\n", test);
    return 0;
}




--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list