The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Need help with C program. I have implement the logic of conway game of life but have problem with reading the input files on the command line.  Check the attachment. I have also attach the input file.  First line contain number of rows and columns for the 2-D matrix.Â
Â
#include <stdio.h>#define HEIGHT 25#define WIDTH 25#define LIFE_YES 1#define LIFE_NO 0// make the rest of the function calls easier to readtypedef int TableType[HEIGHT][WIDTH];void printTable(TableType table) {int height, width;for (height = 0; height < HEIGHT; height++) {for (width = 0; width < WIDTH; width++) {if (table[height][width] == LIFE_YES) {printf("X");} else {printf("-");}}printf("\n");}printf("\n");}// you already have a printTable, no need for this// clear was a better namevoid clearTable(TableType table) {int height, width;for (height = 0; height < HEIGHT; height++) {for (width = 0; width < WIDTH; width++) {table[height][width] = LIFE_NO;}}}void askUser(TableType tableA) {int i;int n;int height, width;printf("Enter the amount of initial organisms: ");scanf("%d", &n);for (i = 0; i < n; i++) {printf("Enter dimensions (x y) where organism %d will live: ", i +1);scanf("%d %d", &height, &width);tableA[height][width] = LIFE_YES;}printTable(tableA);printf("Generation 0");}int getNeighborValue(TableType table, int row, int col) {if (row < 0 || row >= HEIGHT|| col < 0 || col >= WIDTH|| table[row][col] != LIFE_YES ){return 0;} else {return 1;
Attachments: