I'm trying to make an implementation of the datatype RATIONAL in ADT way. The probleme is when I try to allocate memory for a new struct that I create in main.c.
I send the adress of the struct to rational_create, where I try to allocate memory to it and after that set values to the integers in the struct, but the way I try to allocate doesn't work.
the problem is how to allocate the memory in rational_create(rational *r, int n, int t).
The code looks like this:
rational_create(Rational a, 2, 2);
int a1, b1;
void rational_create(Rational *r, int n, int t)
*r = (Rational)malloc(sizeof(struct rat_));
typedef struct rat_ Rational;
void rational_create(Rational *r, int n, int t);
int gcd(int n, int t);
Rational add(Rational r);
Rational sub(Rational r);
and s on...