Print special characters in c that are in a file.txt com local library.h

My college semester program has several screens that print large texts of arquivo.txt, however, as I do in C language, some characters do not appear, such as the ç, é, ã... and so on.

I discovered a library called locale.h. With it you can write some commands that make your program look for the language of your operating system and with this print the special characters . In ubuntu , for example... A Brazilian locality is given by: "pt_BR_utf8".

Follows an illustrative code of my problem:

//Caracteres Especiais - Padrão PT/BR

`#include <locale.h>` 

//Biblioteca para definição de configuração local, necessario para o setlocale

    int main () 
    {
       printf("\nLocalidade Corrente: %s", setlocale(LC_ALL,NULL));
       printf("\nA localidade corrente agora  %s", setlocale(LC_ALL,""));
       //Com esse segundo printf, quer dizer que agora o programa está
       //habilitado a imprimir os caracteres especiais, certo?
       //Porém, eu imprimo o texto na função telaAjuda1() abaixo


       return(0);

    }

    void telaAjuda() {

    //Se o usuario digitar 1 aqui, o switch case vai chamar a função abaixo telaAjuda1(); - Numerei as funções, porque são 88. Achei mais fácil
    //de identificar mais tarde.

    }

    void telaAjuda1 ()
    {


        FILE *arq;
        char Linha[100];
        char *result;
        int i;
        system("clear");
        // Abre um arquivo TEXTO para LEITURA
        arq = fopen("telaAjuda1.txt", "rt");
        if (arq == NULL)  // Se houve erro na abertura
        {
            printf("Problemas na abertura do arquivo\n");
            return;
        }
        i = 1;
        while (!feof(arq))
        {
            // Lê uma linha (inclusive com o '\n')
            result = fgets(Linha, 100, arq);  // o 'fgets' lê até 99 caracteres ou até o '\n'
            if (result)  // Se foi possível ler
    //É no printf abaixo que imprimo o texto
                printf("\t%s",Linha);

            i++;
        }
        fclose(arq);

    }

Note: I thought maybe it could be error in my ubuntu terminal that was not configured to read UTF-8 files, but I went into Settings and it is ok.

Note 2: below is an excerpt of the text that is not printing correctly.

" The Data Structures course discusses several techniques of programming, presenting the basic data structures used in software development.

Knowledge of programming languages alone does not it is necessary to know how to use them from efficient way. The project of a program encompasses the identification of data properties and functional characteristics". - W. Celes and J. L. Rangel

The problem: even I looking in the Ubuntu terminal, and even I putting the locale.h and setting up I'm not understanding why it's not printing correctly.

Author: Marcielli Oliveira, 2015-11-28

1 answers

Have you noticed if the file is in utf-8? I created a file here with its text and without having to include the library locale.h worked perfectly. Follow my test below.

#include<stdio.h>

int main(){
    FILE *fp;
    char string[300];
    fp = fopen("file.txt","r");
    while(1){
        fgets(string,300,fp);
        if(feof(fp)) break;
        puts(string);
    }
    fclose(fp);
    printf("\n");
    return 0;
}

And the result obtained: Result

 1
Author: GustavoR., 2015-11-29 14:57:48