jeudi 6 juin 2019

Problem executing an 'if...else' statement

I have an if...else statement, but the if part doesn't work.

The code is compiled without error but I don't get the desired result.

/*Code to determine what is the largest country in the world*/   


#include<stdio.h>

int main()
{

char ans;

printf("What is the largest country in the world?\n");
scanf("%s", &ans);

if   (ans=="Russia"){printf("Yes!it's %s\n", ans);}
else                {printf("No, it's Russia!\n");}

return 0;
}

I always get this(either when I enter Russia or another word):

No, it's Russia! * stack smashing detected *: ./a terminated

So, how can I solve the problem & what am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire