Passing an array of structs in C

后端 未结 9 886
傲寒
傲寒 2020-12-01 16:33

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
    {
          


        
9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-01 17:13

    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.

提交回复
热议问题