Can someone help me? the error is in the research which is "pesquisar" in portuguese. I just wanna know why it doesn't work. The code is not printing the search result. Any help is good. The code is in portuguese but I think it won't be a problem. Thank u all.
struct fichacarro {
char fabricante[15];
char modelo[15];
char combustivel[10];
char cor[10];
char placa[10];
int ano;
int km;
float preco;
};
int inserir(struct fichacarro carro[], int *x, int *f) {
printf("\nModelo: ");
fflush(stdin);
fgets(carro[*x].modelo, 15, stdin);
printf("Fabricante: ");
fflush(stdin);
fgets(carro[*x].fabricante, 15, stdin);
printf("Combustivel (alcool, gasolina ou diesel): ");
fflush(stdin);
fgets(carro[*x].combustivel, 10, stdin);
printf("Cor (branco, preto ou prata): ");
fflush(stdin);
fgets(carro[*x].cor, 10, stdin);
printf("Placa: ");
fflush(stdin);
fgets(carro[*x].placa, 10, stdin);
printf("Ano: ");
scanf("%d", &carro[*x].ano);
printf("Kilometros: ");
scanf("%d", &carro[*x].km);
printf("Preco: ");
scanf("%f", &carro[*x].preco);
*x = *x + 1;
*f = *f + 1;
system("cls");
}
int excluir(struct fichacarro carro[], int *x, int *f) {
int k, j;
printf("Digite o indice do carro que quer excluir: ");
scanf("%d", &k);
k = k - 1;
if (k>*x || k < 0)
printf("Indice nao existe");
else {
j = k;
while (j<*x) {
strcpy(carro[j].modelo, carro[j + 1].modelo);
strcpy(carro[j].fabricante, carro[j + 1].fabricante);
strcpy(carro[j].combustivel, carro[j + 1].combustivel);
strcpy(carro[j].cor, carro[j + 1].cor);
strcpy(carro[j].placa, carro[j + 1].placa);
carro[j].ano = carro[j + 1].ano;
carro[j].km = carro[j + 1].km;
carro[j].preco = carro[j + 1].preco;
j = j + 1;
}
*x = *x - 1;
*f = *f - 1;
}
}
int pesquisar(struct fichacarro carro[], int *x, int f) {
int y, j;
char cor[10];
float preco;
char fabricante[15];
printf("\n----OPCOES DE PESQUISA----\n");
printf("1 - Ler o nome do fabricante e informar todos os veiculos deste fabricante.\n");
printf("2 - Pesquisar os dados de veículos com o preço dentro de um limite fornecido.\n");
printf("3 - Informar todos os veículos de determinada cor pesquisada\n\n");
printf("Opcao escolhida: ");
scanf("%d", &y);
switch (y) {
case 1:
printf("\nDigite o nome do fabricante: ");
fflush(stdin);
fgets(fabricante, 15, stdin);
j = *x;
while (j < f) {
if (strcmp(fabricante, carro[j].fabricante) == 0);
{
printf("\nCarro: %d", j); // <---it doesn't work
printf("\nModelo: %s\n", carro[j].modelo);// <---it doesn't work
}
j = j + 1;
}
system("pause");
system("cls");
break;
case 2:
printf("Preco limite: ");
scanf("%f", &preco);
j = *x;
while (j < f) {
if (carro[j].preco <= preco);
{
printf("\nCarro: %d", j); // <---it doesn't work
printf("\nModelo: %s", carro[j].modelo); // <---it doesn't work
printf("\nFabricante: %s", carro[j].fabricante);// <---it doesn't work
printf("\nCombustivel: %s", carro[j].combustivel); // <---it doesn't work
printf("\nCor: %s", carro[j].cor); // <---it doesn't work
printf("\nPlaca: %s", carro[j].placa); // <---it doesn't work
printf("\nAno: %d", carro[j].ano); // <---it doesn't work
printf("\nKm: %d", carro[j].km); // <---it doesn't work
printf("\nPreco: %f\n", carro[j].preco); // <---it doesn't work
}
j = j + 1;
}
system("pause");
system("cls");
break;
case 3:
printf("Cor: ");
fflush(stdin);
fgets(cor, 10, stdin);
j = *x;
while (j < f) {
if (carro[j].cor == cor);
{
printf("\nCarro: %d", j); // <---it doesn't work
printf("\nModelo: %s\n", carro[j].modelo); // <---it doesn't work
}
j = j + 1;
}
system("pause");
system("cls");
break;
default:
system("cls");
printf("Nao encontrado.\n\n");
system("pause");
system("cls");
break;
}
}
int main() {
struct fichacarro carro[49];
int n, x = 0, y, cont, f = 0;
printf("Numero de acoes: ");
scanf("%d", &n);
system("cls");
for (cont = 0; cont < n; cont++) {
printf("----OPCOES DE ESCOLHA----\n\n");
printf("1 - Inserir veiculo\n");
printf("2 - Excluir veiculo\n");
printf("3 - Pesquisar veiculo\n");
printf("4 - Sair\n\n");
printf("Opcao escolhida: ");
scanf("%d", &y);
switch (y) {
case 1:
inserir(carro, &x, &f);
break;
case 2:
excluir(carro, &x, &f);
break;
case 3:
pesquisar(carro, &x, f);
break;
case 4:
x = n;
break;
default:
system("cls");
printf("Nao encontrado.\n\n");
system("pause");
system("cls");
break;
}
}
return 0;
}