-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.
– Fábio Morais
The function removeAcento.When you enter there, the comparison does not seem to happen.
– Lucas Correia
When I write "O" will "O" be stored in the variable? Or will it be another character ? This may be the problem
– Fábio Morais
It will be the character O, without accent.
– Lucas Correia
These ascii table values are wrong, that’s why it goes wrong, I to debug the repair program that
á
amounts to-96
– Fábio Morais