You have not specified what element of the array item
you are trying to pass to the function.
item[]
doesn’t mean anything. It has no value. You have to put a number into the brackets. That number is the element of the array. Each element of an array has its own value.
Example broken code where the same mistake is made:
#include <stdio.h>
int main(void)
{
int my_array[3] = {1, 2, 3};
my_array[] = 1; // ERROR HERE!
return 0;
}
If you try to compile this, you will get this:
1.c: In function ‘main’:
1.c:6:11: error: expected expression before ‘]’ token
because I didn’t tell what element of my_array
I want to assign 1 to. Do I want to assign it to the first element (my_array[0]
), the second element, (my_array[1]
), or the third element (my_array[2]
)? The compiler doesn’t know. You have to tell it.
If item
if a scalar (not an array), get rid of the [], it’s not suppose to be there.
In case you are trying to pass the whole array as an argument, you don’t use the brackets even though you are passing an array. If you want to pass the whole array as an argument do this:
if(!saveItems(item, DATAFILE, NoOfRecs))
4
solved Expected expression before ‘]’ token? C [closed]