diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b70bac5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,85 @@ +# manual entries up here +.gdb_history +conway + +# Created by https://www.toptal.com/developers/gitignore/api/cmake +# Edit at https://www.toptal.com/developers/gitignore?templates=cmake + +### CMake ### +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +### CMake Patch ### +# External projects +*-prefix/ + +# End of https://www.toptal.com/developers/gitignore/api/cmake + +# Created by https://www.toptal.com/developers/gitignore/api/c +# Edit at https://www.toptal.com/developers/gitignore?templates=c + +### C ### +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +# End of https://www.toptal.com/developers/gitignore/api/c + diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..96ac2df --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.10) + +project(conway) + +add_executable(conway conway.c) +target_compile_options(conway PUBLIC -ggdb -O0 -Wall) \ No newline at end of file diff --git a/conway.c b/conway.c index c8468a6..0e2f559 100644 --- a/conway.c +++ b/conway.c @@ -1,44 +1,46 @@ +#include +#include +#include #include #include #include -#include -#include #include -#include -void printGrid(int gridX, int gridY, int **arr) { +void printGrid(int gridX, int gridY, int** arr) +{ // print the array for debugging - wprintf(L"%lc", 0x2554); - for(int j = 0; j < gridY; j++) { - wprintf(L"%lc", 0x2550); + wprintf(L"%lc", 0x2554UL); // prints ╔ + for (int j = 0; j < gridX; j++) { + wprintf(L"%lc", 0x2550UL); // prints ═ } - wprintf(L"%lc", 0x2557); + wprintf(L"%lc", 0x2557UL); // prints ╗ wprintf(L"\n"); - for(int j = 0; j < gridY; j++) { - wprintf(L"%lc", 0x2551); - for(int i = 0; i < gridX; i++) { - wprintf(L"%lc", ((arr[i][j] == 1) ? 0x0023 : 0x0020)); + for (int j = 0; j < gridY; j++) { + wprintf(L"%lc", 0x2551UL); // prints ║ + for (int i = 0; i < gridX; i++) { + wprintf(L"%lc", ((arr[i][j] == 1) ? 0x0023UL : 0x0020UL)); } - wprintf(L"%lc\n", 0x2551); + wprintf(L"%lc\n", 0x2551UL); // prints ║ } - wprintf(L"%lc", 0x255A); - for(int j = 0; j < gridY; j++) { - wprintf(L"%lc", 0x2550); + wprintf(L"%lc", 0x255AUL); // prints ╚ + for (int j = 0; j < gridX; j++) { + wprintf(L"%lc", 0x2550UL); } - wprintf(L"%lc", 0x255D); + wprintf(L"%lc", 0x255DUL); // prints ╝ return; } -int main(int argc, char *argv[]) { - if(argc < 3) { +int main(int argc, char* argv[]) +{ + if (argc < 3) { printf("Usage: conway [seed]\n"); exit(255); } setlocale(LC_CTYPE, ""); - int gridX, gridY, seed = 0, generation = 0; - for(int i = argc - 1; i > 0; i--) { - switch(i) { + int gridX = 0, gridY = 0, seed = 0, generation = 0; + for (int i = argc - 1; i > 0; i--) { + switch (i) { case 1: gridX = atoi(argv[i]); break; @@ -50,20 +52,20 @@ int main(int argc, char *argv[]) { break; } } - if(seed == 0) { + if (seed == 0) { time_t t; - srand((unsigned) time(&t)); + srand((unsigned)time(&t)); } else { srand(seed); } // dynamically allocate the 2D array, could be quite large! - int *arr[gridX]; - for(int i = 0; i < gridY; i++) { - arr[i] = (int *)malloc(gridY * sizeof(int)); + int* arr[gridX]; + for (int i = 0; i < gridX; i++) { + arr[i] = (int*)malloc(gridY * sizeof(int)); } // seed the array - for(int i = 0; i < gridX; i++) { - for(int j = 0; j < gridY; j++) { + for (int i = 0; i < gridX; i++) { + for (int j = 0; j < gridY; j++) { arr[i][j] = (rand() % 2 == 0) ? 1 : 0; } }