So this is my code so far.
Code:
#include <stdio.h>
#include <stdlib.h>
#define LUNCHES 5
#define ARRAY 2
int main(void)
{
int x;
struct Food
{
char *name; /* “name” attribute of food */
int weight, calories; /* “weight” and “calories” attributes of food */
}lunch[LUNCHES] = { [0] = {"apple", 4, 100}, [1] = {"salad", 2, 80} };
for(x = ARRAY; x <= LUNCHES; ++x)
{
printf("Please input \"food\", weight, calories: ");
scanf("%d %d", &lunch[x].weight, &lunch[x].calories);
printf("The %s weighs %doz. and contains %d calories", lunch[x].name, lunch[x].weight, lunch[x].calories);
}
return 0;
}
I need to set a temporary buffer for food. Not sure how to do that. Also allocating memory.
I think for allocating:
Code:
Food *buff = malloc(sizeof(name))
Along the lines of it, what do you think?