Reputation: 680
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
Upvotes: 0
Views: 309
Reputation: 272752
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 + "*"
Upvotes: 3
Reputation: 1
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.
Upvotes: 3