How do I overwrite a string with an accent for another without?

-1

I wanted to replace the accented characters with other ones without and generate a new string, but there seems to be something wrong in the comparison I'm trying to do in the extractAcento function. I looked at the ASCII table, but I still did not get the error. Maybe it's the use of the pointer, I do not know.

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

#define num_moveis 4
#define max_caracteres 256
char retiraAcento(char * nome, int tam);
int verificaNome(char * nome, int tam);
char leValidaNome(char * prodAux);
void menu(char moveis[][256]);
int main(int argc, char *argv[]) {
    char moveisDisponiveis[num_moveis][max_caracteres] = {{"sofa"}, {"mesa"}, {"estante"}, {"escrivaninha"}};
    char prodAux[max_caracteres];
    menu(moveisDisponiveis);
    leValidaNome(prodAux);





    return 0;
}
void menu(char moveis[][256]){
    int i=0;
    printf("Relacao dos moveis disponiveis\n\n");
    for(i=0; i < num_moveis; i++){
        printf("%s\n", moveis[i]);
    }
}
char leValidaNome(char * prodAux){
    int tam = 0, flag = 1;
    do{
        //system("cls");
        printf("\nInforme o produto desejado:");
        scanf(" %[^\n]s", prodAux);
        *prodAux = tolower(*prodAux);
        tam = strlen(prodAux);
        retiraAcento(prodAux, tam);
        //printf("%s", prodAux);
        flag = verificaNome(prodAux, tam);
        system("cls");
        if(flag == 0){
            printf("\nNome vazio ou com numeros!\n");
        }



    }while(!flag);

    return *prodAux;
}
int verificaNome(char * nome, int tam){

    int i=0, flag = 1;
    if(tam == 0){
        flag = 0;
    }else{
        for(i; i < tam; i++){
            if(isdigit(nome[i])){
                flag = 0;
            }else{
                flag = 1;
            }
        }
    }
    //printf("%d", flag);
    return flag;
}
char retiraAcento(char * nome, int tam){
//á = 225, à =224 , é=233, è=232, í=237, ì=236, ó=243, ò = 242, ú = 250, ù = 249
//falta acrescentar mais alguns caracteres  
    unsigned char i;

    for(i=0; i < tam; i++){
        if(nome[i] == 225 || nome[i] ==  224){
            nome[i] = 97;
        }else if(nome[i] == 233 || nome[i] == 232){
            nome[i] = 101;
        }else if(nome[i] == 237 || nome[i] == 236){
            nome[i] = 105;
        }else if(nome[i] == 243 || nome[i] == 242){
            nome[i] = 111;
        }else if(nome[i] == 250 || nome[i] == 249){
            nome[i] = 117;
        }
    }
    //printf("%s", nome);
    return *nome;
}
    
asked by anonymous 09.09.2018 / 16:52

1 answer

2

Accents is not supported in the ascii table, so the source of this whole problem is therefore impossible to do.

But you can use this example below to make% debug%, as input put something like prints and thus you see the values " áàéèíìóò " you really want because those values you put are the wrong values. It is possible to use this in your compiler, but if it is for another, most probably no longer gives, as said accents is not part of ascii .

   for(i=0; i<tam; i++){
        printf("%c %d\n", nome[i],(int)nome[i]);
        system("PAUSE");
        if(nome[i] == 160 || nome[i] ==  224){
            nome[i] = 97;
        }else if(nome[i] == 233 || nome[i] == 232){
            nome[i] = 101;
        }else if(nome[i] == 237 || nome[i] == 236){
            nome[i] = 105;
        }else if(nome[i] == 243 || nome[i] == 242){
            nome[i] = 111;
        }else if(nome[i] == 250 || nome[i] == 249){
            nome[i] = 117;
        }
    }
    
09.09.2018 / 17:24