compscistudent
compscistudent

Reputation: 127

Error: expression must be a modifiable l value

I am attempting to multiply each value of an array by an integer, however I am currently encountering the following error: 'expression must be a modifiable lvalue'. The purpose of this code is that, when a button is pressed, the rectangle is enlarged by a scalar factor of 2. How can I resolve this error?

void Draw_Rectangle(unsigned int *rectangle1)
{
    // Call draw rectangle function to draw rectangle 1
    GraphicsFunction_drawRectangle (*rectangle1, *(rectangle1 + 1));

}

int main (void)
{
    unsigned int rectangleOne[4] = {85, 5, 130, 20};
    // Call function to draw the rectangle in initial position
    Draw_Rectangle(&rectangleOne[0]);

   while(1) {

       if(*(SWITCH_ptr) == 512) {
        int i = 0;
        for(i = 0; i < 4; i++){
            &rectangleOne[i] = rectangleOne[i] * 1.5;
        }
        Draw_Rectangle(&rectangleOne[0]);
    }
   }
}

Upvotes: 0

Views: 92

Answers (2)

Tom Karzes
Tom Karzes

Reputation: 24052

Change:

&rectangleOne[i] = rectangleOne[i] * 1.5;

to:

rectangleOne[i] = rectangleOne[i] * 1.5;

or even more simply, just:

rectangleOne[i] *= 1.5;

The problem with the original version is that it was trying to assign to the address of the array element, rather than the array element itself.

Upvotes: 2

0___________
0___________

Reputation: 67476

&rectangleOne[i] = rectangleOne[i] * 1.5; => rectangleOne[i] = rectangleOne[i] * 1.5;

it is enough also to Draw_Rectangle(rectangleOne); as arrays are passed by pointers

Upvotes: 2

Related Questions