For an assignment, I have to declare a struct as follows:
struct Food
{
char *name;
int weight, calories;
} lunch[5] = {
{
"apple", 4, 100
},
{
"salad", 2, 80
}
};
In my main, I am trying to ask the user for the rest of the inputs to fill the struct to print them out. I figure I would try to use malloc. Would I do something like this?
int main(void)
{
char *str1;
printf("Please enter a food, weight, and calories of the food: ");
scanf("%s", (char *)malloc(str1));
return(EXIT_SUCCESS);
}