【发布时间】:2015-05-01 03:14:23
【问题描述】:
我正试图让这个程序说好,但它说好 虽然我使变量值与 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;
}
【问题讨论】:
-
使用
strcpy和strcmp分配和比较字符串 -
您正在比较指针,因此出现错误。还有
man 3 strcmp.
标签: c if-statement chars