If I have struct inside another struct and I am trying to have them inside an array

jeff

I have a struct that is named item, now I have another struct that is called array that calls item. The struct item arrayofListis required to be of the size 5

#include <stdio.h>
#include <string.h>
#define MaxItems 5
#define NameLength 20
#define UnitLenght 6



struct item
{
    char name[NameLength];
    float amount;
    char unit[UnitLenght];
};
struct array
{
    struct item arrayofList;
};

int main(void)
{
    struct array shopping[MaxItems];

Am I giving the list size of 5 or am I doing it incorrectly

Jabberwocky

You probably want this:

#include <stdio.h>
#include <string.h>

#define MaxItems 5
#define NameLength 20
#define UnitLenght 6

struct item  // one item
{
    char name[NameLength];
    float amount;
    char unit[UnitLenght];
};

int main(void)
{
    struct item shopping[MaxItems];  // array of MaxItems struct items
    ...
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

I am new to golang, I am trying to create a zip that must have a folder inside that is: tosend.zip/archivos/file.png

How to have many structs inside a struct?

How to access golang Struct Array inside another Struct?

Malloc an array inside a struct

can i use "int" as my dynamic array inside a struct?

I am trying to push values from an object inside an array

Creating array of struct inside another struct

Can I have non-static struct inside a static vector

Can I have an orderable inside another orderable?

trying to get the value of the struct inside an array

I am new to REACT, I have to call a function resetArray which is inside my sorting class component from another file onClick of a button

how do I assign a value to a struct array inside a struct in c?

in Coldfusion how do I add a 'column' to the struct inside an array?

How can I update a table that has struct inside a struct and both structs are inside an array? ARRAY<STRUCT<STRUCT>>

How do I use malloc for an array of structs inside another struct that has been created using malloc

I am trying to position an info box over an image but still have both stay inside the container

Reallocating array inside struct

Assign a struct to another struct inside a struct in C

I have an array inside another array and i want the value of the last element

initialize an array of structs inside another struct

How can i add a value in an Array which is inside a struct (Swift)

realloc of array inside a struct

Is it ok to have a class inside a struct?

Once I have the the foundation results in the console, How to put them in a struct?

I want to access a general struct field inside another struct's field in C

how can i have a struct have an unknown size array member?

Swift filter an array inside a struct by another array

Creating an array of struct inside another struct and accessing the members of the struct inside the array in C

Array assignment inside a Struct