mardi 25 octobre 2016

Calling a method in if statement breaks down variables

I have a code like this

int i;
for(i=0; i<n ; i++)
{
    ....

    if( isSeatAvailable(&tmp, movie_name, seat_number, &ref_error) == 0)
    {
        printf("available %s\n", seat_number);
    }
    else
    {
        logError(ref_error);
    }

    ....
}

If isSeatAvailable returns 0, it works perfectly, but it returns -1 and the program continues to else statement, the variables breaks down: like n becomes 4509408 etc.

The thing is, If I re-write code like this and call isSeatAvailable method outside of if statement, it works perfect!

int i;
for(i=0; i<n ; i++)
{
    ....

    int res = isSeatAvailable(&tmp, movie_name, seat_number, &ref_error);
    if( res == 0)
    {
        printf("available %s\n", seat_number);
    }
    else
    {
        logError(ref_error);
    }

    ....
}

What might cause the problem here?

Aucun commentaire:

Enregistrer un commentaire