how to assign multiple values into a struct at once?

Try this:

Foo foo;
foo = (Foo){bunch, of, things, initialized};

This will work if you have a good compiler (e.g. GCC).

Update: In modern versions of C (but not C++), you can also use a compound literal with designated initializers, which looks like this:

foo = (Foo){ .bunch = 4, .of = 2, .things = 77, .initialized = 8 };

The name right after the “.” should be the name of the structure member you wish to initialize. These initializers can appear in any order, and any member that is not specified explicitly will get initialized to zero.

Leave a Comment