I wrote a C program to evaluate reverse polish notation by passing the expression as a command line argument, but when I pass * (for multiplication) then it is passing all the file names in that folder.

For example I passed this :

./rpn 10 20 30 + *

and when I print all the arguments result is,

 10
 20
 30
 +
 gcd
 gcd.c
 gcd.c~
 rpn
 rpn.c
 rpn.c~
 swapmacro
 swapmacro.c argc :12
有帮助吗?

解决方案 2

You need to escape the * e.g. by quoting it like "*" or by escaping it like \*

The expansion of * is done by the shell (before starting your program). Read e.g. the Advanced Bash Scripting guide.

其他提示

This is not a C problem. You're using Bash (or some equivalent shell), where * is automatically expanded (before it gets anywhere near your program). You'll need to do something like this:

./rpn 10 20 30 + "*"
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top