执行'if ... else'语句时出现问题

时间:2019-06-06 08:25:00

标签: c if-statement

我有一个 if ... else 语句,但是 if 部分不起作用。

代码编译没有错误,但是我没有得到想要的结果。

/*Code to determine 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;
}

我总是得到这个(当我输入俄罗斯或其他字词时):

  

不,是俄罗斯!    *检测到堆栈粉碎** :./已终止

那么,我该如何解决问题以及我在做什么错呢?

1 个答案:

答案 0 :(得分:0)

字符正好是一个字符长,它永远不能与字符串匹配。

相关问题