#include <stdio.h>
/* Terry Harvey CISC105 Section 21 TA Aaron*/

/* Sample program using struct pointers */

struct rational {
    int numer;
    int denom;
    struct rational * next;
};

int main(){
    int numer, denom;
    int i = 0;
    struct rational * newRat, * temp;

    newRat = (struct rational *)malloc( sizeof(struct rational) );

    printf("Enter a numerator and denominator, or denom == 0 to stop: ");
    scanf("%d%d", &newRat->numer, &newRat->denom);
    printf("address of this struct rat is %p\n", newRat);
    printf("rat is %d / %d\n", newRat->numer, newRat->denom);

    //make a second struct rat
    newRat->next = (struct rational *)malloc( sizeof(struct rational) );

    printf("Enter a numerator and denominator, or denom == 0 to stop: ");
    scanf("%d%d", &newRat->next->numer, &newRat->next->denom);
    printf("address of this struct rat is %p\n", newRat->next);
    printf("rat is %d / %d\n", newRat->next->numer, newRat->next->denom);

    //makes the second rational point to the first rational to form a cycle
    newRat->next->next = newRat;

    temp = newRat;
    while(temp != NULL){
        printf("address of this struct rat is %p\n", temp);
        printf("rat is %d / %d\n", temp->numer, temp->denom);
        temp = temp->next;
    }

    return 0;
}
