[英]error: invalid operands to binary % (have ‘struct Fraction *’ and ‘struct Fraction *’)
I am trying to create a simple program which accepts a numerator and denominator and then divides it and display simplified form. 我正在尝试创建一个接受分子和分母的简单程序,然后将其除以显示简化形式。 When I compile the program I get the following error and I am unable to understand what the error is:
当我编译程序时,出现以下错误,我无法理解错误是什么:
workshop9.c: In function ‘simplify’:
workshop9.c:30:14: error: invalid operands to binary % (have ‘struct Fraction *’ and ‘struct Fraction *’)
workshop9.c:31:14: error: invalid operands to binary / (have ‘struct Fraction *’ and ‘int’)
Here are the lines where I get the error: 这是我收到错误的行:
25 void simplify(struct Fraction *var1, struct Fraction *var2) {
26
27 int num1;
28 int num2;
29
30 num1 = var1 % var2;
31 num2 = var2 / 10;
32 }
You cannot use operator
%
on a structure
in C
. 您不能在
C
的structure
上使用operator
%
。
Instead access its member variable
directly which is of native-type
integer
. 而是直接访问其
member variable
,该member variable
是native-type
integer
。
For example: 例如:
num1 = var1->somemember % var2->somemember;
num2 = var2->somemember / 10;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.