表达式必须是可修改的L值
我这里有char text[60];
然后我做了一个if
:
if(number == 2) text = "awesome"; else text = "you fail";
并且它总是说表达式必须是可修改的L值。
您无法更改text
的值,因为它是一个数组,而不是指针。
将它声明为char指针(在这种情况下,最好将其声明为const char*
):
const char *text; if(number == 2) text = "awesome"; else text = "you fail";
或者使用strcpy:
char text[60]; if(number == 2) strcpy(text, "awesome"); else strcpy(text, "you fail");