Expression must be a modifiable L-value

不想你离开。 提交于 2019-11-28 21:01:56

问题


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-value.


回答1:


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");


来源:https://stackoverflow.com/questions/6008733/expression-must-be-a-modifiable-l-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!