Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试将scanf算术操作数转换为变量。我想将“+”放入变量中。我尝试了我发现的一切,但到目前为止没有任何效果。我带来的最好的东西是:
scanf
char plus = "+"; char* c; scanf("%c", &c); if (strcmp(plus, c) == 0) { printf("you have + in variable");
但这不起作用。似乎“+”没有进入变量plus,也没有使用scanf. 这有什么诀窍吗?
plus
里面有多个错误:
char*
char
%c
char**
strcmp
如果您正在处理单字符运算符,则无需做比它们更复杂的事情:
char plus = '+'; char c; scanf("%c",&c); if(plus == c) printf("you have + in variable");