ant2009 ant2009 - 1 year ago 233
C Question

lvalue required as increment operand

gcc 4.4.4

What am I doing wrong?

char x[10];
char y[] = "Hello";
while(y != NULL)
*x++ = *y++;

Many thanks for any advice.

Answer Source

x++ is the short form of x = x + 1. However, x here is an array and you cannot modify the address of an array. So is the case with your variable y too. What you can do is defined two pointers pointing to the two arrays and increment those pointers or do the following.

 char x[10];
 char y[] = "Hello";
 int i=0;
 while(y[i] != 0)
     *(x+i) = *(y+i);
 x[i] = 0;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download