Passing an array of structs in C


I'm having trouble passing an array of structs to a function in C.

I've created the struct like this in main:

int main()
{
    struct Items
    {
        char code[10];
        char description[30];
        int stock;
    };

    struct Items MyItems[10];
}

I then access it like: MyItems[0].stock = 10; etc.

I want to pass it to a function like so:

 ReadFile(MyItems);

The function should read the array, and be able to edit it. Then I should be able to access the same array from other functions.

I've tried heaps of declarations but none of them work. e.g.

void ReadFile(struct Items[10])

I've had a look around for other questions, but the thing is they're all done different, with typedefs and asterisks. My teacher hasn't taught us pointers yet, so I'd like to do it with what I know.

Any ideas? :S

EDIT: Salvatore's answer is working after I fixed my prototype to:

void ReadFile(struct Items[10]);

Answers:


struct Items
{
    char code[10];
    char description[30];
    int stock;
};

void ReadFile(struct Items items[10])
{
    ...
}

void xxx()
{
    struct Items MyItems[10];
    ReadFile(MyItems);
}

This in my compiler works well. What compiler are you using? What error you got?

Remember to declare your struct before your functions or it will never work.