Problem using SetLocale in C

-2

Everyone, good morning. I'm starting in C programming (I come from Python and JavaScript).

I have a problem using the setLocale function, which defines the type of language used, allowing the use of accentuation and so on. When I put the function in my program and enter any value with the use of the point (example: 0.4) the program ends instantially. I know the error is in setLocale, because when I take the function the program runs as expected.

Below is my code:

The purpose of using SetLocale (which is to use accent and tals) works correctly,     

asked by anonymous 05.03.2018 / 00:39

4 answers

0

Hello, I think your problem is that setlocale () is passing the Brazilian numeric base where we use "," instead of "." which is the default. Try to run your code using commas, it should work.

    
01.04.2018 / 23:52
0

Calling setlocale( LC_ALL, "" ); (with the second parameter blank), causes the default locale of the program to be set automatically according to the environment variables of your system:

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

int main(void)
{
    setlocale( LC_ALL, "" );
    printf( "ÁÉÍÓÚ\n" );
    return 0;
}
    
05.03.2018 / 14:24
0
#include <stdio.h>
#include <locale.h>
int main(){
    setlocale(LC_ALL, "Portuguese");
    printf("Olá Mundo");
    return 0;
}

The first letter should be uppercase, Lacobus gave you a hint to automatically set the setlocale of your program, but if you want to do it manually, type Portuguese with the first capital letter.

    
06.03.2018 / 04:09
0

Prove:     setlocale (LC_ALL, "portuguese-brazilian");

    
06.03.2018 / 16:13