سؤال

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