devxlogo

Assigning C-strings

Assigning C-strings

Question:
I am just beginning to learn C++ and I’ve stumble on an error that I cannot figure out despite all my efforts. Here is the code where I’m having trouble with. Thank you for any help that you can provide.

 //a sub function to sort a global arrayvoid sortArray(phoneAddress info[]){   //declare variables   char lastName[25] = "";   char swap ='Y';   while (swap ='Y')   {      swap ='N';      for (short x = 0; x 

Error Message on all 3 is this: "'=':left operand must be I-value."

Answer:
You cannot assign a C-string using operator =. Instead, use strcpy() for that purpose.

devx-admin

Share the Post: