How can I use malloc to create memory instead of assigning the pointer below to an instance of this struct?
Code:
struct fraction {
int numerator;
int denominator;
};
struct fraction *stanford;
I am looking to do something like below but I know this dont work
Code:
stanford = (int *) malloc(sizeof());
So for now I am stuck doing it this way:
Code:
struct fraction thistime;
stanford = &thistime;
And then the goal is to do something like below using malloc (very basic for now):
Code:
stanford->numerator = 100;
stanford->denominator = 200;
printf("%d is stanford numerator and %d\n", stanford->numerator);