我试图在 switch 中使用格式说明符,但是编译器返回错误:表达式结果未使用
const char* text;
const char* input;
int i=2;
input = "orange";
switch(i){
case 1:
text = "%s is color", input;
break;
case 2:
text = "%s is fruit", input;
break;
default:
break;
}
最佳答案
您想使用 sprintf或 snprintf。
char text[128];
const char* input;
int i=2;
input = "orange";
switch(i){
case 1:
sprintf(text, "%s is color", input);
break;
case 2:
sprintf(text, "%s is fruit", input);
break;
default:
break;
}
关于c - 如何在 C 中的 switch 中使用格式说明符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51185885/