尝试从命令行获取星号*作为主输入 [英] Trying to get an asterisk * as input to main from command line
问题描述
我尝试从命令行发送输入到我的主要功能。然后将输入发送到函数checkNum等。
int main(int argc,char * argv [])
{
int x = checkNum(argv [1]);
int y = checkNum(argv [3]);
int o = checkOP(argv [2]);
...
}
它应该是一个计算器,当我写命令行时:
program.exe 4 + 2
pre>
它会给我答案6(这个代码不包括在内)。
是我想要乘法,我输入例如
program.exe 3 * 4
它似乎创建一个指针(或某事,不太确定),而不是给我的char指针的字符'<$ c $问题是我可以得到输入'
'的行为方式,当我输入'+'?*
编辑:在命令行中编写
*
是否有一种方式,我只需要键入*
?
代码运行在Windows上,
解决方案如果你不想使用单引号(
'
)或双引号()。
#set -o noglob
或
#set -f
pre>
(两者都是等效的)。
关闭shell的globbing。 t展开任何glob,包括
*
。I'm trying to send input from the command line to my main function. The input is then sent to the functions checkNum etc.
int main(int argc, char *argv[]) { int x = checkNum(argv[1]); int y = checkNum(argv[3]); int o = checkOP(argv[2]); … }
It is supposed to be a calculator so for example in the command line when I write:
program.exe 4 + 2
and it will give me the answer 6 (code for this is not included).
The problem is when I want to multiply and I type for example
program.exe 3 * 4
It seems like it creates a pointer (or something, not quite sure) instead of giving me the char pointer to the char '
*
'.The question is can I get the input '
*
' to behave the same way as when I type '+'?Edit: Writing
"*"
in the command line works. Is there a way where I only need to type*
?The code is running on Windows, which seems to be part of the problem.
解决方案You can turn off the shell globbing if you don't want to use single quote (
'
) or double quote ("
).Do
# set -o noglob
or
# set -f
(both are equivalent).
to turn off the shell globbing. Now, the shell won't expand any globs, including
*
.这篇关于尝试从命令行获取星号*作为主输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!