表达式必须是可修改的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\");
    

要回复问题请先登录注册