这是Kernighan和Ritchie撰写的The C Programming Language的程序练习(第5章)。在此程序中,当我使用“ *”作为乘法运算符时,指针** argv指向argv [0],即1st(Zeroth)参数,并读取第一个字符“ P”而不是“ *”。
执行后,带有参数: ./ProgE5-10 +124 -3 * =
它返回错误的答案,而不是-372。
但是,如果将“ *”替换为“ x”,则程序可以正常运行。所有其他操作(即+,-,/,=)也可以正常工作。
请告诉我为什么*使argv指向程序名称。
//Exercise 5-10. Write the program expr, which evaluates a reverse Polish
//expression from the command line, where each operator or operand is a
//separate argument. For example, expr 2 3 4 + *
//evaluates 2 x C+4).
//For multiplication character '*' is not working
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#define MAXLINE 1000
#define NUMBER 0
int sign = 1;
char s[MAXLINE]; …Run Code Online (Sandbox Code Playgroud) c ×1