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

//typedef struct nodeR* node;
struct nodeR {
	char name[50];
	struct nodeR* next;
};
typedef struct listR* list;
struct listR {
	struct nodeR* head;
	struct nodeR* tail;
	int size;
};

// create list
list list_create(){
	list l;	//struct listR* l;
	l = (list)malloc(sizeof(struct listR));
	if (l == NULL){
		return NULL;
	}
	l->head = NULL;	//(*l).head = NULL
	l->tail = NULL;
	l->size = 0;

	return l;
}

// destroy list
void list_destroy(list l){
	struct nodeR* curnode = l->head;
	while (curnode != NULL){
		struct nodeR* tmp = curnode->next;
		free(curnode);
		curnode = tmp;
	}
	free(l);
}

// return true iff list is empty
int list_isempty(list l){
	if (l->size == 0){
		return 1;
	}
	return 0;
}

// push new name at the end of the list
void list_push_back(list l, char *name){
	struct nodeR* newnode = (struct nodeR*)malloc(sizeof(struct nodeR));
	if (newnode == NULL){
		abort();
	}
	
	int i=0;
	while(name[i] != '\0'){
		newnode->name[i] = name[i];
		i++;
	}
	newnode->name[i] = '\0';
	
//	strcpy(name, newnode->name);

	newnode->next = NULL;

	if (list_isempty(l)){
		l->head = newnode;
		l->tail = newnode;
		l->size = 1;
	} else {
		struct nodeR* last = l->tail;
		last->next = newnode;
		l->tail = newnode;
		l->size++;
	}
}

void printlist(list l){
	struct nodeR* curnode = l->head;

	while(curnode != NULL){
		printf("%s\n",curnode->name);
		curnode = curnode->next;
	}
}

int main() {
	char buffer[50];
	list l = list_create();
	while( fgets(buffer,49,stdin) ) {
		list_push_back( l, buffer );
	}

	printlist(l);

	list_destroy(l);
}












