All I’m trying to do is initialize my array to all 0s in C, but my compiler keeps giving me errors (and the errors aren’t helpful). The array has 24 entries and the values are floating point values.
main()
{
/* Array of users arrival & departure time */
float user_queue[24];
/* Initialize queue to 0 */
int i;
for(i = 0; i < 24; i++)
{
user_queue[i] = 0.0;
}
/* Simulation time */
float time = 0;
The compiler is giving me an error on the “float time” line. The error goes away if I remove my for loop.
syntax error : missing ; before type
You’re overrunning the array by 1 element. Try this instead:
Change the
<=to<.EDIT : With new information.
You’re probably compiling in C89/90 or ANSI C mode. In those older C revisions, variable declarations must be at the start of the function or scope. You can’t intermingle declarations and code like that.
Try this: