-1
good night. I’ll be direct..
I’m an ADS student and I’m in my second semester..
I need to develop a rotating parking system. In this the user needs to insert the vehicle plate and we must assign to it whether it is aged, pne or standard, and also the time of entry of the vehicle in the parking. However I am not able to do even the first part of the exercise that would register a plate and then find it in the vector where it was registered.
Follow the code and ask me to help me find where I’m going wrong.
#include <stdio.h>
#include <stdlib.h>
char placa[5];
int op;
void cadastro ();
void pesquisaPlaca ();
int main () {
cadastro ();
pesquisaPlaca ();
return 0;
}
void cadastro (){
do {
char placa1;
printf ("\ndigite a placa do veiculo:");
scanf ("%s",&placa[placa1]);
printf ("digite 1 para novo cadastro ou 0 para sair:");
scanf ("%d",&op);
placa1++;
} while (op==1);
}
void pesquisaPlaca (){
char placaPesq;
int j;
printf ("\ninsira a placa a ser pesquisada:");
scanf ("%s",&placaPesq);
fflush(stdin);
for (j=0;j<=placa;j++) {
if (strcmp(placa[j], placaPesq)) {
printf ("\nplaca %s encontrada.", placa[j]); // nao localiza a placa
} else {
printf ("\nplaca nao encontrada");
}
}
}
Note that here:
char placa1; printf ("\ndigite a placa do veiculo:"); scanf ("%s",&placa[placa1]);
you declareplaca1
but does not assign any value to the variable. When using inplaca[placa1]
the variableplaca1
will contain memory junk.– anonimo