La expresión debe ser un valor L modificable


Tengo aquí char text[60];

, Entonces lo hago en un if:

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

Y siempre decía que la expresión debe ser un valor L modificable.

Author: emlai, 2011-05-15

1 answers

No puede cambiar el valor de text ya que es un array, no un puntero.

O bien declararlo como puntero char (en este caso es mejor declararlo como const char*):

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

O use strcpy:

char text[60];
if(number == 2) 
    strcpy(text, "awesome"); 
else 
    strcpy(text, "you fail");
 34
Author: MByD,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-05-15 13:45:33