gpt4 book ai didi

c - 将用户输入作为运算符放入表达式中

转载 作者:太空宇宙 更新时间:2023-11-04 05:45:51 24 4
gpt4 key购买 nike

是否可以将用户输入作为变量用于表达式中?

scanf("%s", op); //User enters "==" or "!="

if(x op y)
//Go.

最佳答案

没有。你能做的最好的事情是:

scanf("%s", &op);
if (strcmp(op, "==") == 0) {
result = x == y;
}
else if (strcmp(op, "!=") == 0) {
result = x != y;
}

// now use result

关于c - 将用户输入作为运算符放入表达式中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5413906/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com