【发布时间】:2009-11-10 07:43:34
【问题描述】:
对于赋值,我必须声明一个结构如下:
struct Food
{
char *name;
int weight, calories;
} lunch[5] = {
{
"apple", 4, 100
},
{
"salad", 2, 80
}
};
在我的主要内容中,我试图向用户询问其余的输入以填充结构以将它们打印出来。我想我会尝试使用malloc。我会做这样的事情吗?
int main(void)
{
char *str1;
printf("Please enter a food, weight, and calories of the food: ");
scanf("%s", (char *)malloc(str1));
return(EXIT_SUCCESS);
}
【问题讨论】: