#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <limits.h>
#include <assert.h>

#define MAXCOLS  256
#define MAXROWS  256


/* Data type: Labyrinth - ASCII map, costs, direction */

typedef struct labyrinth
{
   char lab[MAXCOLS+2][MAXROWS];
   long costs[MAXCOLS][MAXROWS];
   long bestx[MAXCOLS][MAXROWS];
   long besty[MAXCOLS][MAXROWS];
   int maxrow;
   int startx;
   int starty;
   int treasurex;
   int treasurey;
}LabCell, *Lab_p;

//prototypes
Lab_p LabRead(FILE* in);
void printLab(Lab_p);

int main(int argc, char* argv[])
{
	FILE *in = stdin;
   	Lab_p lab = NULL, handle;
   	char* inp;

   	if(argc > 2)
   	{
      		fprintf(stderr, "Usage: %s [<file>]\n", argv[0]);
     	 	exit(EXIT_FAILURE);
   	}
   	if(argc == 2)
   	{
      		in = fopen(argv[1], "r");
      		if(!in)
      		{
        		perror(argv[0]);
        	 	exit(EXIT_FAILURE);
      		}
	}
	lab = LabRead(in);
	printLab(lab);
	return 0;
}



Lab_p LabRead(FILE* in)
{
	char buff[MAXCOLS];
	int x = 0;
	char value;
	printf("allocating space\n");
	Lab_p map = malloc(sizeof(Lab_p));
	printf("allocated space\n");
	while(feof(in))
	{
		fgets(buff,MAXCOLS,in);
		strcpy(map->lab[x],buff);
		x++; 
	}
	return map;
}

void printLab(Lab_p lab)
{
	char buff[MAXCOLS];
	int i = 0;
	for(i; i < MAXROWS;i++)
	{
		strcpy(buff,lab->lab[i]);
		printf("%s \n",buff);
	}
}
