samedi 17 juin 2017

Invalid If statement output in C [duplicate]

This question already has an answer here:

I am learning the C programming language, I am attempting to do an If statement in which if the user inputs "hey" in reads the var is hey, if not it reads, the var is not hey, however, when executing, even when hey is inputed, it reads, the var is not hey, how can I fix this?

#include <stdio.h>
void main(void){
        char var[3];
        printf("Enter your name: ");
        scanf("%s", &var);
        printf("%s", &var);
        printf("\n");
        if(var == "hey"){
                printf("The var is hey");
        }
        if(var != "hey"){
                printf("The var is not hey");
        }
        printf("\n");
        }

Aucun commentaire:

Enregistrer un commentaire