Search code examples
cdata-structureslinked-liststructure

Returning a nested structure from a function


I am writing code in which I want to return a nested structure. I wonder how to do that.

    static int ORDERID = 0;
    struct item
    {
        struct data
        {
            int orderid;
            char content[10][20]; 
        } details;
        struct node *next;
    };
    typedef struct item product;

So insertion of a new product contains two parts:

  1. details structure

  2. pointer pointing to next product

In the details structure I have to have different types of product description, say:

  1. Shoes with its orderid, and other details in the array of strings (char content[10][10])

  2. Shirt with its orderid, and other details in the array of strings (char content[10][10])

So for the insertion of a new product I need a function to return a details structure i.e the nested structure of the product.

How to do that?


Solution

  • You can use struct data as the return type of a function