Problem using Setlocale in C

Asked

Viewed 3,044 times

-2

Hey, guys, 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 etc. When I put the function in my program and type any value using the dot (example: 0.4) the program terminates instanttaneously. I know the error is in the setLocale, because when I take the function the program runs as expected.

Below is my code:

inserir a descrição da imagem aqui

Note: The purpose of using Setlocale (which is to use accentuation and tals) works correctly, I just don’t understand the error.

  • 1

    Include the code always as text and format it with Ctrl-k or by using the button {} of the editor

4 answers

0

#include <stdio.h>
#include <locale.h>
int main(){
    setlocale(LC_ALL, "Portuguese");
    printf("Olá Mundo");
    return 0;
}

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

0

The call of setlocale( LC_ALL, "" ); (with the second blank parameter), 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;
}

0


Hello, I believe your problem is that setlocale() is passing the Brazilian numerical base where we use "," instead of "." which is the standard. Try running your code using commas, it should work.

0

Prove: setlocale(LC_ALL, "English-Brazilian");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.