I was doing an exercise in the C Programming Language (exercise 5-10), where I have to create a reverse polish notation calculator. Everything is working except for multiplication, and I can't figure out why! Addition, subtraction and division work out, but the case for multiplication never actually gets executed for some reason, it jumps straight to the default. When I started printing out the value of c, it printed out a c as the last argument instead of a '*'. I'm assuming this c was from the first letter of the program name calc, so it's going to the first argument instead of the last or something weird. Here's my code:
Umm... thats weird. Whenever I run it it gives me an error. I tried running "2 3 *" and it said "error: invalid character." I changed the multiplication symbol to 'x', ran "2 3 x", and it worked perfectly! Strange stuff... might have something do with the fact I'm running linux.
The problem isn't with your code, it's because you're passing command-line arguments from the linux shell.
When you run the code with exe 2 3 *, your linux shell expands the '*' to be all the files in the current directory. So your code is probably seeing "2 3 file1 file2 ... filen".
What you could do is quote the *, so enter exe 2 3 "*", or similar. Then the actual '*' character will be passed in.
Haha, didn't see that coming. So it's interpreting it as the operator that can fill in any character(s) in a file/directory name, that's kind of awesome and annoying at the same time. Good catch!