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

Can I have non-static struct inside a static vector

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

Is it ok to have a class inside a struct?

Creating array of struct inside another struct

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

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

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

Can I have an orderable inside another orderable?

How to have many structs inside a struct?

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

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

trying to get the value of the struct inside an array

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

Swift filter an array inside a struct by another array

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

Assign a struct to another struct inside a struct in C

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

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

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

initialize an array of structs inside another struct

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

How to access golang Struct Array inside another Struct?

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

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

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

Malloc an array inside a struct

Array assignment inside a Struct

realloc of array inside a struct

Reallocating array inside struct