I have this code

char powerUpPDF[3]; void DemoGL::powerUpCheck(){ powerCheck->toggle(); char status_OK[] = "OK"; char status_NO[] = "—" if (powerCheck->isChecked()){ powerUpPDF = status_OK; }else{ powerUpPDF = status_NO; } } 

According to the idea, it should assign powerUpPDF, the value of status_OK, but it shows me an error invalid array assignment .

  • four
    eh ... use strcpy (), cannot be assigned through = lines. - pavel
  • @pavel strcpy (powerUpPDF, status_OK); like this? - Insider
  • one
    yes (10 characters) - pavel
  • Credit quotes „“ in the code wormed. From a Word that you copied? - αλεχολυτ
  • @alexolut is not, the code was rewritten in the standard Makovsky (I do not like Windows) application "Notes", since the code on one machine ... without a network, etc. :) cross-compiling in this case is not really working yet :) - Insider

1 answer 1

To assign strings, use the strcpy or strncpy functions. The second function also checks that no more than the specified number of characters is copied.

 if (powerCheck->isChecked()) { strcpy(status_OK, powerUpPDF); } else { strncpy(status_NO, powerUpPDF, 3); }