Joe Woods
Joe Woods

Reputation: 83

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 }

Upvotes: 0

Views: 475

Answers (1)

Neijwiert
Neijwiert

Reputation: 1025

You cannot use operator % on a structure in C.

Instead access its member variable directly which is of native-type integer.

For example:

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

Upvotes: 2

Related Questions