Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: C++
Expertise: Beginner
Jan 18, 2000

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 array
void sortArray(phoneAddress info[])
{
   //declare variables
   char lastName[25] = "";
   char swap ='Y';

   while (swap ='Y')
   {
      swap ='N';

      for (short x = 0; x < 6; x++)
      {
         if (stricmp(info[x].nameL, info[x + 1].nameL)==-1)
         {
            swap ='Y';
         lastName = info[x].nameL;// error
            info[x].nameL = info[x+1].nameL;// error
            info[x+1].nameL = lastName;// error
         }   //end if
      }   //end for
   }   //end while
   for (short x = 0; x < 6; x++)
        // sub function
   displayInfo(info, x);
}   // end function
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 Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date