简体   繁体   English

错误:对二进制%无效的操作数(具有“结构分数*”和“结构分数*”)

[英]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 . 您不能在Cstructure上使用operator %

Instead access its member variable directly which is of native-type integer . 而是直接访问其member variable ,该member variablenative-type integer

For example: 例如:

num1 = var1->somemember % var2->somemember;
num2 = var2->somemember / 10;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:二进制&lt;&lt;的无效操作数(具有“ struct str *”和“ int”) - error: invalid operands to binary << (have ‘struct str *’ and ‘int’) 二进制 + 的无效操作数(具有 'struct student' 和 'int') - invalid operands to binary + (have 'struct student' and 'int') 二进制操作数无效!=(具有结构和 void *) - Invalid operands to binary != (have struct and void *) 二进制*的操作数无效(有&#39;ab {aka struct a}&#39;和&#39;ab * {aka struct a *}&#39;) - Invalid operands to binary * (have ‘ab {aka struct a}’ and ‘ab * {aka struct a *}’) 用c中的struct计算分数 - calculating the fraction with struct in c 将错误无效操作数编译为二进制 &amp;&amp;(具有 'int' 和 'pthread_t' {aka 'struct<anonymous> '})</anonymous> - Compiling error invalid operands to binary && (have 'int' and 'pthread_t' {aka 'struct <anonymous>'}) 找到最大的分数 - 结构问题 - Find the biggest fraction - struct question 二进制表达式的无效操作数(&#39;struct node&#39;和&#39;struct node&#39;) - invalid operands to binary expression ('struct node ' and 'struct node ') 错误:对二进制+无效的操作数(具有“ float *”和“ float *”) - error: invalid operands to binary + (have 'float *' and 'float *') 错误:对二进制^无效的操作数(具有&#39;char *&#39;和&#39;char *&#39;) - error: invalid operands to binary ^ (have ‘char *’ and ‘char *’)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM