C Program only reading first License Plate

2.3k Views Asked by At

So i've been through a problem , i have to make a cab programm for school , so , i hava an case in which i need to give user an option to change the car avaliablity , but for that the user's need to give the license plate in order to proceed. As i add two vehicles to struct , on case 3 , the program is only accepting license plate 1 as correct...

void alterarDisponiblidadeTaxi (TAXIS taxis[], int qtd_taxis ){
int i=0;
char matr[10];
if(0>=qtd_taxis){
    printf("No data has given yet!\a\n");
    return; }
printf("Insert the vehicle's plate:\n");
scanf("%s",matr);

if (strcmp(matr,taxis[i].matricula) == 0){
    printf("License plate found with sucess!\n");
    return 0;
}
if (strcmp(matr,taxis[i].matricula) != 0){
        printf("License plate not found with sucess!\a\n");
        return 0;
}
}
1

There are 1 best solutions below

1
On BEST ANSWER

I think you forgot to add a forloop. As i=0, it will only check for the first Licence plate.

void alterarDisponiblidadeTaxi (TAXIS taxis[], int qtd_taxis ){
    int i=0;
    char matr[10];
    if(0>=qtd_taxis){
        printf("No data has given yet!\a\n");
        return; }
    printf("Insert the vehicle's plate:\n");
    scanf("%s",matr);

    for(int i=0; i<qtd_taxis; i++) {
        if (strcmp(matr,taxis[i].matricula) == 0){
            printf("License plate found with sucess!\n");
            return 0;
        }
    }

    printf("License plate not found with sucess!\a\n");
    return 0;
}