#include	<stdio.h>
#include	<stdlib.h>
#include	<string.h>

#define BUFFER_LEN	20
typedef char t_name[BUFFER_LEN];

typedef struct {
	t_name	name;
	int	num;
} t_course;

typedef struct node {
	t_course	 course;
	struct node	*next;
} t_node;

int
main()
{
	t_course course[] = {
		{ "COMP3710",	25 },
		{ "COMP3724",	20 },
		{ "COMP4718",	15 }
	};
	int	i   = 0;
	t_node *list = NULL;	/* Pointer to the front of the list */
	t_node *it = NULL;	/* Iterator */

	/* Fill up the list */
	for (i = 0; i < sizeof(course)/sizeof(course[0]); ++i) {
		t_node *cur = (t_node *) malloc(sizeof(t_node));

		strcpy(cur->course.name, course[i].name);
		cur->course.num = course[i].num;

		cur->next = list;	/* Insert node at front of list */
		list = cur;		/* Update the front of the list */
	}

	/* Display the list */
	for (it = list; it != NULL; it = it->next)
		printf("%s: %d\n", it->course.name, it->course.num);

	/* Free up the list */
	while (list) {
		t_node	*del = list;
		list = list->next;
		free(del);
	}

	return 0;
}
