jeudi 5 septembre 2019

Will an If inside An If always be read? Not nested, but put right in front of the last one

The second if is always executing, no matter what the values from the first one was, I´m comparing char arrays from a struct.

Tried doing all of the comparisons in one If, like this:

if(strcmp(t[j].NomePeca,t[n].NomePeca) == 0 && strcmp(t[j].nroPoltrona,t[n].nroPoltrona) == 0 && strcmp(t[j].hora,t[n].hora) == 0 && strcmp(t[j].data,t[n].data) == 0){

Same thing.


struct TabelaIngresso
 {
    char NomePeca[30];
    char data[10];
    char hora[5];
    int aPagar;
    char nroPoltrona[3];
};

............................


    if(strcmp(t[j].NomePeca,t[n].NomePeca) == 0 && strcmp(t[j].nroPoltrona,t[n].nroPoltrona) == 0)
                    {
                         if((strcmp(t[j].hora,t[n].hora) == 0) && (strcmp(t[j].data,t[n].data) == 0))
                         {

                                anulado = 1;
                                printf("\nCompra anulada pois a poltrona nao esta disponivel!\n");
                                strcpy (t[j].NomePeca, "Anulado");
                                strcpy (t[j].data, "Anulado");
                                strcpy (t[j].hora, "Anulado");
                                t[j].nroPoltrona[3] = '0';
                                t[j].aPagar = 0;

                            }



This If should only be executed if all of the strings are the same.

Aucun commentaire:

Enregistrer un commentaire