Heya everyone. I am a first-year student and doing a project for my C class. It is to do with John Conway's "Game of Life" as I am sure you are all aware of what that is. Here is the things needed. And after that is the code that I have. I have done everything up to printing the original config that the user gives. I would like a little help on how to reset the grid to show the next generation though. Thanks so much.
Write a C program that:
* Reads coordinates entered by the user until a -1 is entered. Be sure to check each pair for validity assuming all inputs are integers. If a user enters an invalid value, ask the user to enter both coordinates again. If an invalid value is read froma file, terminate the program with an error message.
* Asks the user how many generations to calculate.
* Prints the initial configuration using an "*" for occupied cells and a "-" for unoccupied cells.
* Calculate and print successive generations.
* Print the generation number above the grid, print the statistics stating how many cells were "born" and how many cells "died" during this generation, then print the grid.
* Make sure that your prompts and outputs use EXACTLY the same format as the example.
You are to write at least 4 functions (note that I didn't specify the parameters or return values of these functions):
* initconfig( ) which reads in the initial configuration
* generate( ) which creates and prints a new generation of organisms
* occ( ) which returns the number of occupied cells around cell[x,y]
* printgrid( ) which prints a grid
#include <stdio.h>
#define SIZE 10
#define SIZE2 15
void initconfig(int [][SIZE2], int, int, int);
void printgrid(int [][SIZE2], int, int );
int main ()
{
int coordArray[SIZE][SIZE2] = {0}, x = 0, y = 0,
generations = 0;
initconfig(coordArray, x, y, generations);
printf("\n\n\nInitial State\n\n");
printgrid(coordArray, SIZE, SIZE2);
return 0;
}
void initconfig(int coordArray[][SIZE2], int x, int y, int generations)
{
printf("\nEnter the number of generations: ");
scanf("%d", &generations);
printf("\nEnter coordinates: ");
scanf("%d%d", &x, &y);
while (x != -1){
if(x<1 || x>10 || y<1 || y>15)
printf("\nInvalid input.");
else
coordArray[x-1][y-1] = 1;
printf("\nEnter coordinates: ");
scanf("%d%d", &x, &y);
}
}
void printgrid(int coordArray[][SIZE2], int row, int col)
{
int i, j;
printf("\n");
for(i=0; i <= row - 1; i++){
for(j=0; j <= col - 1; j++){
if(coordArray[i][j] == 1){
printf("*");}
else
printf("-");}
printf("\n\n");
}
}