lvalue required as increment operand

前端 未结 9 1696
清歌不尽
清歌不尽 2020-12-04 15:56

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.

9条回答
  •  Happy的楠姐
    2020-12-04 16:25

    char x[10];
    char y[] = "Hello";
    char *p_x = &x[0];
    char *p_y = &y[0];
    while(*p_y != '\0') *p_x++ = *p_y++;
    

    Since you can't modify the array addresses (done by x++ and y++ in your code) and you can modify the pointer address, I copied over the address of the array into separate pointers and then incremented them.

    If you want, I'm sure you can reduce the notation, but I hope you got the point.

提交回复
热议问题