C编程语言:if语句与字符无法正常工作

tal*_*raa 1 c if-statement chars

我试图让这个程序说得好但是它说好了但是我把变量值与if测试值相同

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char history[200];
    history == "NY school";

    if(history == "NY school")
    {
        printf("good");
    }
    else{printf("okay");}
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Ed *_*eal 5

您需要使用该功能 strcmp

  if (strcmp(history ,"NY school") == 0) ....
Run Code Online (Sandbox Code Playgroud)

否则你正在比较指针

再加上变化

  history == "NY school";
Run Code Online (Sandbox Code Playgroud)

使用 strcpy