开发者

Expression must be a modifiable L-value

开发者 https://www.devze.com 2023-03-05 20:13 出处:网络
I have here char text[60]; Then I do in an if: if(number == 2) text = \"awesome\"; else text = \"you fail\";

I have here char text[60];

Then I do in an if:

if(number == 2)
  text = "awesome";
else
  text = "you fail";

and it always said expression must be a modifiable L-v开发者_如何学Goalue.


lvalue means "left value" -- it should be assignable. You cannot change the value of text since it is an array, not a pointer.

Either declare it as char pointer (in this case it's better to declare it as const char*):

const char *text;
if(number == 2) 
    text = "awesome"; 
else 
    text = "you fail";

Or use strcpy:

char text[60];
if(number == 2) 
    strcpy(text, "awesome"); 
else 
    strcpy(text, "you fail");
0

精彩评论

暂无评论...
验证码 换一张
取 消