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

struct coor{
	int x;
	int y;
	struct coor *next;
};

struct coor *first = NULL;

void addition( int x, int y );
void printing();
void close();


int main( int argc, char**argv ) {

	char direction;        
	int x, y;

	do{

		// Get input...
		fprintf( stderr, "1. Input\n" );
		fprintf( stderr, "2. Print\n" );
		fprintf( stderr, "3. Exit\n" );
		scanf(" %c", &direction);

		// Run the selective command
		switch(direction){
			case '1':				
				// Get the coordinate
				fprintf( stderr, "Input x coordinate as Integer : " );
				scanf(" %d", &x);

				fprintf( stderr, "Input y coordinate as Integer : " );
				scanf(" %d", &y);

				addition( x, y );
				break;

			case '2':
				printing();
				break;

			case '3':
				printf("Exiting\n");
				close();

				return 0;

			default:
				printf("Invalid input\n");
				break;

		}

	} while(1); 

	return -1;

}

// memory allocate & initializing function
struct coor* alloc( int x, int y ){

	struct coor* tmp;

	tmp = (struct coor*) malloc( sizeof(struct coor) );
	tmp->x = x;
	tmp->y = y;
	tmp->next = NULL;

	return tmp;

};

void addition( int x, int y ){

	struct coor* tmp;


	if( first == NULL )
		first = alloc( x, y );

	else {
		// find last node ;)
		for( tmp = first ; tmp->next != NULL ; tmp = tmp->next );
		tmp->next = alloc( x, y );
	}

}

void printing(){

	struct coor* tmp;
	int num = 1;

	fprintf( stderr, "Num   X   Y\n" );
	for( tmp = first ; tmp != NULL ; tmp = tmp->next, num++ )
		fprintf( stderr, "%3d %3d %3d\n", num, tmp->x, tmp->y );

}


void close(){

	struct coor *tmp;
	
	while( first != NULL ){

		tmp = first;
		first = first->next;

		free( tmp );

	}

}

