Cannot compare variables in C

Asked

Viewed 12 times

0

My code should recognize the character "(". But unfortunately it does not recognize, and I do not know why. Breakable Ahead starts with "(", but when I compare it to '(', it falls on the last Esol, failing to execute the first conditional. The line you should compare is: if (&Lookahead == '('). The problem that happens is that I compare a char type with another char, but ends up not even enter in the condition

char lookahead;   

int F(char palavra[], int *pos){
printf("lookahead no F: %s", &lookahead);
if (&lookahead == '('){
    if (match('(', palavra, pos) && S(palavra, pos) && match(')', palavra, pos) ){
      printf("F deu true no (");
      return 1;
    }
    else {
        printf("F deu false no (");
        return(0);
    }
}
else if(lookahead == 'N'){
    if (N(palavra, pos)){
      printf("F deu true no N");
      return(1);
    }
    else {
        printf("f deu false no N");
        return(0);
    }
}
else if(lookahead == '-'){
    if (match('-', palavra, pos) && N(palavra, pos)){
        printf("F deu true no -");
        return(1);
    }
    else {
        printf("F deu false -");
        return(0);
    }
}
else{
    printf("F deu false pois nao entrou em nenhum");
    return 0;
}

}

int main(){
char palavra[30];

printf("Digite a palavra: ");
scanf(" %s", &palavra);

int  pos=0;

printf("palavra na posição 0: %s", &palavra[0]);

lookahead = palavra[pos];

printf("lookahead: %s", &lookahead);

if (I(palavra, &pos))
    printf("\nPalavra %s reconhecida\n", palavra);
else
    trataErro();
system("PAUSE");
return(0);

}

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.