How do I overwrite a string with another accent without?

Asked

Viewed 169 times

-1

I wanted to replace the accented characters with others without and generate a new string, only that there seems to be something wrong in the comparison I’m trying to do in the function withdrawAcento. I consulted the ASCII table, but I still do not understand the error. Maybe it is 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;
}
  • What piece of code problems then? In ascii table does not support seats.

  • The function removeAcento.When you enter there, the comparison does not seem to happen.

  • When I write "O" will "O" be stored in the variable? Or will it be another character ? This may be the problem

  • It will be the character O, without accent.

  • These ascii table values are wrong, that’s why it goes wrong, I to debug the repair program that á amounts to -96

1 answer

2


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

But you can use this example below do the prints debug, as input put something like áàéèíìóò and so sees the values "ascii" that you really want, because those values that you put down are the wrong ones. It is possible to use this in your compiler, but if it goes to another one, it probably does not, as I said accents is not part of the 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;
        }
    }
  • I got it, Fábio. I should have done this, but I ended up taking the wrong decimal values in the table. I’m going to correct here. Anything, I come back.

Browser other questions tagged

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