0

Here are the structure declarations:

typedef struct line { int width; char *theLine; } Line; typedef struct screen { int width; int height; Line *theScreen; } Screen; 

Here is what I am using to try an initialize the Screen structure:

int main() { Screen b = {20, 40, {40, "-"}}; } 

When I compile the above the result is:

warning: braces around scalar initializer [enabled by default] Screen b = {20, 40, {40, "-"}}; ^ 

What am I doing wrong in the structure initialization? Also, once I am able to compile the code above, how would I access each member of the Line variable withing the struct screen? Any help is greatly appreciated, thank you.

1 Answer 1

1

You've defined the 3rd member as a pointer. With Line theScreen; instead of Line *theScreen;, your initialization code would work.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for the reply. I realized this as well, but I believe it to be part of the assignment to make it work with a pointer.Even though it seems inefficient.
@WillyFiallo Screen b = {20, 40, &(Line){40, "-"}};
(^One way to allocate the Line struct and get a pointer to it)
Thank you for your help!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.