if (i=0)
That's assignment, not equality comparison.
int i;
Also, i
is uninitialized, so accessing its value is undefined behavior. Since you accidentally assigned to it instead of comparing to it, if (i=0)
doesn't invoke undefined behavior, but it would if you fixed the first bug.
i++;
printf("%d", number[i]);
Incrementing i
before the print means you always print the cell right after the one you were working on.
You don't actually need i
; t
does everything you want i
to do. We'll remove i
and rename t
to i
:
for (int i = 0; i < 5; i++) {
if (i == 0) {
number[i] = rand() % 8 + 1;
} else {
number[i] = rand() % 10;
}
printf("%d", number[i]);
}