如果逻辑条件带有C中的字符串

时间:2013-06-02 18:00:45

标签: c string equality

puts("Type your name");
gets(name);
if(name=="exit"){
    exit(0);
}

我的逻辑条件是,如果错了,我该如何修复它?

2 个答案:

答案 0 :(得分:2)

由于name是一个字符串,为什么不使用strcmp函数?

if (strcmp(name, "exit") == 0)
{
  exit(0);
}

答案 1 :(得分:1)

您无法比较字符串,使用strcmp,或者最好使用strncmp