Conway's Game of Life

Implementing Conway's Game of Life in C

Mar 02, 2020

2 minutes


Built with


For this coursework we were to implement Conway’s Game of Life in C. This consists of a DLL and a program that calls the library for key functionality.

Dynamically Linked Library

This was to implement a range of functions

  1. read_in_file() reads in the file from the filepointer infile and stores the universe in the structure pointed to by u. You must use dynamic memory allocation.
  2. write_out_file() writes the content of the universe pointed to by u into the file from the file pointer outfile
  3. is_alive returns 1 if the cell in that column and row is alive and 0 otherwise
  4. will_be_alive() returns 1 if that cell in that column and row will be alive in the next generation and 0 otherwise, assuming that cells outside the universe are always dead
  5. will_be_alive_torus() returns 1 if the cell in that column and row will be alive in the next generation and 0 otherwise, assuming a torus topology
  6. evolve() changes the universe from the current generation to the next generation. It used the function pointed to by the function pointer rule
  7. print_statistics() should calculate the percentage of cells that are alive in the current generation and the average percentage that have been alive in all the generations so far

It also had to support multiple universe structures in memory at the same time

The main challenge of this was to use dynamic memory allocation, whereby the program allocates memory as it is scanning the input file.

Command line program

The program had to take a range of inputs to pass to the library, they can be seen as follows

Build system

I also had to create a makefile to compile both the library and command line program using GCC. The output of this was a program and a .so library. The makefile also implements make clean to remove all the files produced during compilation