
/* Program plays John Conway's "Game of Life" */
#include "life.h"

int main(int argc, char *argv[])
{
    char string [MAXLEN];  /* Holds input from the user */
    char board [BOARDX][BOARDY];  /*  Array contains the status
                                          of the life board */
   if (argc >= 2){        /* If we have too many arguments print an error */
       print_usage();
        return -1;
   } else if (argc == 2) {
		strcpy (string, argv[1]);
   } else {
		printf ("Input a file name to load\n");
		printf ("(It must be in the same directory as your project)\n");
		fgets (string, MAXLEN, stdin);
		string[strlen(string)-1] = '\0';
   }
    
    /* Read the board from disk - exit the program if there is an error */
    if (read_board (string,board) == ERROR) 
        return -1;
   
    while (1) {    /* Loop around until the user types quit */
        print_board(board);
        printf (
          "\nType quit to exit, or anything else to continue\n");
        fgets (string, MAXLEN, stdin);
        if (strcmp (string, "quit\n") == 0)
           return 0;
        update_board(board);
    }
	return 0;
}


void print_usage (void)
/* Print instructions on how to use the program */
{
    fprintf (stderr, "life [filename]:\n");
    fprintf (stderr, "    Play Conways \"Game of Life\" on a given file.\n");
}



