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;
}