我在代码中使用了结构。看起来一切正常,我不太确定为什么会产生此错误。我觉得我已经明确声明了struct运算符。仍然出现以下错误:
operators undeclared (first use in this function)
这是我的代码:
#include<stdio.h>
#include <stdlib.h>
#include "input.h"
#include "operations.h"
typedef int (*arithmeticFcn)(int, int);
struct operators
{
char symbol;
char opName[10];
arithmeticFcn fcn;
};
int main()
{
int opNum, res;
struct operators calc[4] =
{
{'+', "Add", addition},
{'-', "Subtract", subtract},
{'*', "Multiply", multiply},
{'/', "Divide", divide}
};
for(int i=0; i<4; i++)
{
int j= rand() % 4;
struct operators temp = calc[i];
operators[i] = calc[j];
calc[j] = temp;
printf("%d or %s: %s", i, operators.symbol, operators.opName);
}
printf("Enter Hotkey: ");
scanf("%i || &c", &opNum, &operators.symbol);
res = (operators[opNum || operators.symbol]) (op1, op2);
printf("%i %c %i = %i", op1, operators.symbol, op2, res);
return 0;
}