-2

How can I solve this problem?

error: expected an expression

 for (int i = 0; i < n; i++){
     ^

Function that I try to implement:

void initRacks(struct rack_t *racks, int n) {
  for (int i = 0; i < n; i++){
    racks[i].widthA = i + 2.5;
    racks[i].widthB = i + 1.5;
  }
}
SilverShroud
  • 15
  • 1
  • 6

1 Answers1

1

It depends on which version your compiler is. Declaring the int i; above the for loop will solve the error.

More detailed answer: C for loop int initial declaration