ant2009 ant2009 - 5 months ago 82
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.


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;