I have the following code so far, I am pretty sure I can make the explicit initialization with multiple statements but I want to learn how to do it with a single one.
#include <stdio.h>
#include <stdlib.h>
#define LUNCHES 5
int main(void)
{
struct Food
{
char *n; /* “n” attribute of food */
int w, c; /* “w” and “c” attributes of food */
}
lunch[LUNCHES],
lunch[0] = {"apple pie", 4, 100},
lunch[1] = {"salsa", 2, 80};
}
I am thinking the following would work but it is another statement.
int main(void)
{
struct Food
{
char *n; /* “n” attribute of food */
int w, c; /* “w” and “c” attributes of food */
}
lunch[LUNCHES];
lunch[0] = {"apple pie", 4, 100};
lunch[1] = {"salsa", 2, 80};
lunch[0] = (struct Foot){"apple pie", 4, 100};which was introduced in C99.