-1
char activity[30];
int choice;

scanf("%d", &choice);
if(choice==1){
    activity = "Sedentary";
}
else if(choice==2){
    activity = "Light Activity";
}
else if(choice==3){
    activity = "Moderate Activity";
}
else if(choice==4){
    activity = "Very Active";
}
else if(choice==5){
    activity = "Extra Active";
}

当我编译时,它显示 lvalue required 错误。不知道是什么意思,谁能帮帮我。对不起我的英语。

已编辑 - 标题 TurboC(错字)

4

2 回答 2

1

在 C 中,您必须使用strcpy()来复制字符串。

#include<string.h>

...

if(choice==1){
    strcpy(activity, "Sedentary");
}
else if(choice==2){
    strcpy(activity, "Light Activity");
}
else if(choice==3){
    strcpy(activity, "Moderate Activity");
}
else if(choice==4){
    strcpy(activity, "Very Active");
}
else if(choice==5){
    strcpy(activity, "Extra Active");
}
于 2013-10-30T12:17:58.147 回答
0

activity = "Sedentary";是数组的起始地址,如果您正在执行上面的代码,那么您就像0x123344 = "Sedentary" 这样所以在这里使用 strcpy()

strcpy(activity, "Sedentary");

那么它不应该显示左值错误。

于 2013-10-30T12:32:11.827 回答