-2
I am a beginner in C, I am doing a college activity and trying to compare a data obtained via scanf with a data saved in a registry array that I believe but even entering the same value, always returns false, independent of the comparison method.
my struct:
// Struct Veiculo
typedef struct
{
char marca[50];
char modelo[50];
int anofab;
Placa placa;
} Veiculo;
// Struct Veiculos (Container para veículo)
typedef struct
{
int count;
Veiculo v[10];
} Veiculos;
Where I get the value:
Veiculos frota;
char temp[50];
printf("Insira o modelo: ");
scanf("%s", &temp);
filtrarmodelo(&frota, temp);
Where do I compare:
void filtrarmodelo(Veiculos *frota, char modelo[50])
{
printf("\n\n---------- [LISTANDO MODELO SELECIONADO] ----------\n\n");
// Se não houver veículos, cai aqui
if (frota->count == 0)
{
printf("\nNada para mostrar aqui :(\n\n");
}
else
{
for (int i = 0; i < frota->count; i++)
{
// Compara o modelo inserido com os modelos salvos anteriormente
if (strcmp(frota->v[i].modelo, modelo))
{
printf("%s %s, %d. Placa %s-%s\n\n",
frota->v[i].marca,
frota->v[i].modelo,
frota->v[i].anofab,
frota->v[i].placa.letras,
frota->v[i].placa.numeros);
}
else
{
printf("\nNenhum modelo encontrado :(\n\n");
}
}
}
}
The output I got at the last run was that no model was found.
Gee, thanks a lot, pal. Now if you can explain something to me, why did my question get two negative votes? I don’t use the stack overflow much so I haven’t really caught the dynamics of the site. about the lack of information I thought it would be too much code and mess up the question so I put only the part involved in the problem. thanks again.
– paraguassu
To improve your question you need to read the text of this link. And it also has the text next to the Page of creation of questions.
– Henrique Hott