Reputation: 909
On both for loops (ie: for(len... and for(wid... ), I receive the same error message:
error: expected ';' before ')' token
void
init(void)
{
//fills board up with numbers
int tile = (d*d - 1);
int len = 0;
int wid = 0;
for(len < d; len++)
{
for(wid < d; wid++)
{
board[len][wid] = tile;
tile--;
}
}
}
Sorry to ask a similar question as before, but I'm a very confused Newbie!
Upvotes: 0
Views: 2755
Reputation: 143037
Every for-loop needs to have its 3 parts (initialization, test, update) and if you don't have one or more of them, you still have to supply the two ;
, so
for(len < d; len++)
^
|
should really be
|
v
for(;len < d; len++)
and the same for the other for-loop in your function.
For instance, this is how you would set up an infinite loop using for
:
for(;;)
where all parts are skipped, but the two semi-colons are still required.
Perhaps this is tutorial/reference on the for-loop is helpful as a review/reference.
Upvotes: 5
Reputation: 13097
In general, a for loop has three parts:
for (initialization; check; update) { ... }
In your code, you are missing the initialization section. You are missing a semi colon in your for loops to denote that you don't need an initialization clause (since you do it above):
void
init(void)
{
//fills board up with numbers
int tile = (d*d - 1);
int len = 0;
int wid = 0;
for(;len < d; len++)
{
for(;wid < d; wid++)
{
board[len][wid] = tile;
tile--;
}
}
}
Upvotes: 5