0

i'm trying to write code in C,which implements a simple calculator.

the input should come from the command line, so for example i if i run

./calculator 5 * 2

the result should be 10

the problem is that when i write * it shows all the files in the current directory and the program doesnt behave well.

there is anyway to overcome this problem?

i tried to find here or in other sites solutions,without success.

i need that * will Be interpreted as a char and not as a linux command.

thanks.

Matan
  • 109
  • 2
  • 13

1 Answers1

4

In linux shell, the * has special meaning. It is meant for globbing unless it is quoted like below

./calculator 5 '*' 2

You may also escape the asterisk to strip the special meaning from it

./calculator 5 \* 2
sjsam
  • 21,411
  • 5
  • 55
  • 102