我正在创建一个反向波兰符号计算器,它还可以做一些其他的事情argv[]
来输入选项。但是现在,我只有 RPN 计算器选项,我遇到了一个奇怪的错误,我需要帮助。
我收到错误消息:
Undefined first referenced
symbol in file
fmod /var/tmp//ccGTG20S.o
ld: fatal: Symbol referencing errors. No output written to project
collect2: ld returned 1 exit status
这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
void push(float stack[], float value, int *currStack)
{
int i = *currStack;
while (i != 0)
{
stack[i] = stack[i-1];
i--;
}
stack[0] = value;
*currStack += 1;
}
void pop(float stack[], char operation, int *currStack)
{
int i;
switch (operation)
{
case 'A':
stack[0] = stack[1] + stack[0];
break;
case 'S':
stack[0] = stack[1] - stack[0];
break;
case 'X':
stack[0] = stack[1] * stack[0];
break;
case 'D':
stack[0] = stack[1] / stack[0];
break;
case 'M':
stack[0] = fmod(stack[1], stack[0]);
break;
default:
printf("error: the symbol %c is neither a supported operator nor an integer\n", operation);
break;
}
for (i=1;i<*currStack;i++)
{
stack[i] = stack[i+1];
}
*currStack -= 1;
}
void decode(char **instring, float *outval, int size)
{
int i=0, currStack=0;
float stack[size/2];
for (i=1;i<size;i++)
{
if (atof(instring[i]))
push(stack, atof(instring[i]), &currStack);
else
pop(stack, *instring[i], &currStack);
*outval = stack[0];
}
}
int evaluate(int argc, char *argv[])
{
float result;
decode(argv, &result, argc);
printf("%.2f\n", result);
return 0;
}
int
main(int argc, char *argv[])
{
if( (argc>1 )&&(strcmp(argv[1],"-e")!=0) && (strcmp(argv[1],"-c")!=0) && (strcmp(argv[1],"-g")!=0)){
fprintf(stderr, "%s: option %s is unsupported\n", argv[0], argv[1]);
}
if ((argc>1) && strcmp(argv[1], "-e")==0)
{
evaluate(argc, argv);
}
else if ((argc>1) && strcmp(argv[1],"-c")==0)
{
}
else if ((argc>1) && strcmp(argv[1],"-g")==0)
{
}
return EXIT_SUCCESS;
}