Program for loop syntax errors

90 views Asked by At
#include<stdio.h>
#include<conio.h>
#include<string.h>


int fun1(int *_array)
{
    for(int i = 0; i < 5; i++) {
        printf("\nenter an input\n");
        scanf("%f", &_array[i]);
    }

}
int main()
{
    int _array[5];
    int sum;

    fun1(&_array[5]);

    printf("\nInput    Value    Address\n");
    for(int i = 0; i < 5; i++) {
        printf("%d          %_array          %_array\n", i, _array[i], &_array);
    }
    for(int s = 0; s < 5; s++) {
        sum += _array[s];
    }
    printf("The sum of these values is %d", sum);
    getch();
}

I try to compile this and I get a long list(28 errors) of errors. They appear to be mostly syntax and undeclared identifier errors, in the three for loops I have, but they don't make sense because the loops and counters appear to be written and declared properly. Can any one explain/see what I am doing wrong?

I am also encountering similar issues on other programs I have written recently that include for loops, so any help/insight would really help

1

There are 1 answers

0
pmg On

Perhaps you are using a C89 compiler?

C99 introduced a few new things, among which are the definition of variables in the for control group.

for (int i = 0; i < 1; i++) printf("%d\n", i); // only C99
//   ^^^^ new stuff in C99

The same loop, in C89 syntax would have to be

int i;
for (i = 0; i < 1; i++) printf("%d\n", i);