Hi, I get Runtime ERROR : Segmentation fault with my code: could anyone please help me with that! ( C PROGRAMMING) : GAME OF LIFE
CAUsers)s2828One 1081.cC File Edit View Selection Find Packages Help s1C2 Atom 1081.c 1084c 1025. 1015.c 1013.c next Generation7 princf %s in Hel ue need to updute generat ions ch tin rintsin H howAray(curvrent Generation,nos, cols update current_Ceneration,next Generat ion,rows,cols); stepn funct ion to udete new generat ians es void update char orig ceneration, chan now Generation, int ros, int cols orig Generationi1rin-new Geverationilril: printf("%s\p SNTK" ); e need this function to clear or free op the heap void Clearchar First rray, char Secon Aray, int rows* nt 1; free(First Array[i): That's for eleents in each ra in the First Array 19 free(First Anray): that's for the pointer of the First Anray free(Second ArrayTE:that's for elerents in each ow in the Second 124 rea(Second Annay):7 thats for the pototer of the Secand Annay 127 2 void showArray(char 'myArrayl, int ros, int cols)f CRLF UTF 8GitHub Git (0)1 update 1081.c 162:1 02:14 CAUsers)s2828One 1081.cC File Edit View Selection Find Packages Help s1C2 Atom 1081.c 1084c 1025. 1015.c 1013.c void shhray(ch nyrray1, int rous, int colsy for (int 1-j
43 && counter'1 ess counter2c cols-1)){ if (nyArray [counteri][counter2 1]- 'x') live+; if myArray[counter1+1][counter211]-- X') live+; check don sargin else if((counter! ros -1) && (counter2 ounter2c cols -1)){ -- f (nyArrayLcounter1JLcounter2 -1]-x) livcrt: if (nyArray (counter1 1][counter2 1]--x live++ if (mytrray[counter1 -1lcounter? 1. 'x) alivo++ f (nyarrayLcounter1 -1]counter2 +1]-x) 288 livcrt: if myArray[counter1][counter2 t1)-- "X') live++ 1081.c 244:1 CRLF UTF8 C GitHub +Git (0) !update 02:14 08/03/20194 1081.cCUsers)s28 File Edit View Selection Find Packages Help sic2-Atom 1081.c 1084. 1015.c 1013.c else 1f((counter1--@j(counter2 >ess counter2c cols-1)){ if (nyArray [counteri][counter2 1]- 'x') live+; if myArray[counter1+1][counter211]-- X') live+; check don sargin else if((counter! ros -1) && (counter2 ounter2c cols -1)){ -- f (nyArrayLcounter1JLcounter2 -1]-x) livcrt: if (nyArray (counter1 1][counter2 1]--x live++ if (mytrray[counter1 -1lcounter? 1. 'x) alivo++ f (nyarrayLcounter1 -1]counter2 +1]-x) 288 livcrt: if myArray[counter1][counter2 t1)-- "X') live++ 1081.c 244:1 CRLF UTF8 C GitHub +Git (0) !update 02:14 08/03/20194 1081.cCUsers)s28 File Edit View Selection Find Packages Help sic2-Atom 1081.c 1084. 1025. 1015.c 1013.c elsel if (myArray[counterl 111[counter2 11] -x) live++ if(myarray[counter1 +11Icounter2]X") alivo++ live; if (myArray[counterl ][counter2 1x') live++ live; if (myArray[counterl -11[counter2] -- 'x) live++ if(nyrray[counter1 -1]counter2 +11 x") alivo++ 327 live; neturn alive++ 1081.c 244:1 CRLF UTF8 C GitHub +Git (0) !update 08/03/20194 CAUsers s28281One s1C2 Atom File Edit View Selection Find Packages Help 1081.c 1084c 1025. 1015.c 1013.c include include function ther prints out an array void showArray(Char ,,myArrayl. nt nus, int cols); funct chat conts nurs of Live ne ighbours n int live Cells(char >nyarray, int canteri, nt caiinter? , int reus, int cols); 19 void updte(char. 6.orag Generation, char."new Generation, int ros, int cols); ur gaso 12 void Gane(char "current Gcneration, char "next_Gencration, int rows, int cols, int nunol Stopa): void Clearchar First Array, har *erond Array, int rows); int sain) int rons, colunns,nunofsteps, counter char* current_Ceneration 21 char" next Ganenation get inout scanf(.%d %d %d", &rows, &columns, &nunOfStep4); sperty the nopded eeiry for pous ol Lowed by a for Locp to speci/y the nocded nceory for col current Generation -allor(ssizeof(char)); for (countor-e;counterrows; countor) current Generation[counter1 -malloc(colums sizeof(char)) check for memory if there is no enough enory then exit f(current Generation- "')( print XcERRIR exit(l); specify he needed rerory for ows for next Generution 1 next Gieneratian -callec (rows, sizeaf(cha)) 42 for (counter-8: counter colunns; countora) next Generation[counter1 -calloc(colunns ,sizeof(char)) 1081.c 162:1 CRLF UTF8 GitHub +Git (0) |update 02:14 CAUsers)s2828One 1081.cC File Edit View Selection Find Packages Help sic2-Atom 1081.c 1084c 1025. 1015.c 1013.c next Generation[counter1 -calloc(colunns ,sizeof(chan)) check for memory if there is no enough nenory then exi if(next Generat ion AR1L printis ERRr exit(1); : take input for eoch row for (counter ; cunter3 live calls(current Generation, 1.1.rcus,cols)e2 )) else 1f (curent Generation( 11" live Calls(curent Generation, 1.j.roes,cols)--3) next Generationfilrin-x else if (current Genertionfilm && live cells(current Genertion, .i-os,cols>3)) .. 1081.c 162:1 CRLF UTF8 C GitHub +Git (0) |update 02:14 CAUsers)s2828One 1081.cC File Edit View Selection Find Packages Help s1C2 Atom 1081.c 1084c 1025. 1015.c 1013.c next Generation7 princf %s in Hel ue need to updute generat ions ch tin rintsin H howAray(curvrent Generation,nos, cols update current_Ceneration,next Generat ion,rows,cols); stepn funct ion to udete new generat ians es void update char orig ceneration, chan now Generation, int ros, int cols orig Generationi1rin-new Geverationilril: printf("%s\p SNTK" ); e need this function to clear or free op the heap void Clearchar First rray, char Secon Aray, int rows* nt 1; free(First Array[i): That's for eleents in each ra in the First Array 19 free(First Anray): that's for the pointer of the First Anray free(Second ArrayTE:that's for elerents in each ow in the Second 124 rea(Second Annay):7 thats for the pototer of the Secand Annay 127 2 void showArray(char 'myArrayl, int ros, int cols)f CRLF UTF 8GitHub Git (0)1 update 1081.c 162:1 02:14 CAUsers)s2828One 1081.cC File Edit View Selection Find Packages Help s1C2 Atom 1081.c 1084c 1025. 1015.c 1013.c void shhray(ch nyrray1, int rous, int colsy for (int 1-j 43 && counter'1 ess counter2c cols-1)){ if (nyArray [counteri][counter2 1]- 'x') live+; if myArray[counter1+1][counter211]-- X') live+; check don sargin else if((counter! ros -1) && (counter2 ounter2c cols -1)){ -- f (nyArrayLcounter1JLcounter2 -1]-x) livcrt: if (nyArray (counter1 1][counter2 1]--x live++ if (mytrray[counter1 -1lcounter? 1. 'x) alivo++ f (nyarrayLcounter1 -1]counter2 +1]-x) 288 livcrt: if myArray[counter1][counter2 t1)-- "X') live++ 1081.c 244:1 CRLF UTF8 C GitHub +Git (0) !update 02:14 08/03/20194 1081.cCUsers)s28 File Edit View Selection Find Packages Help sic2-Atom 1081.c 1084. 1015.c 1013.c else 1f((counter1--@j(counter2 >ess counter2c cols-1)){ if (nyArray [counteri][counter2 1]- 'x') live+; if myArray[counter1+1][counter211]-- X') live+; check don sargin else if((counter! ros -1) && (counter2 ounter2c cols -1)){ -- f (nyArrayLcounter1JLcounter2 -1]-x) livcrt: if (nyArray (counter1 1][counter2 1]--x live++ if (mytrray[counter1 -1lcounter? 1. 'x) alivo++ f (nyarrayLcounter1 -1]counter2 +1]-x) 288 livcrt: if myArray[counter1][counter2 t1)-- "X') live++ 1081.c 244:1 CRLF UTF8 C GitHub +Git (0) !update 02:14 08/03/20194 1081.cCUsers)s28 File Edit View Selection Find Packages Help sic2-Atom 1081.c 1084. 1025. 1015.c 1013.c elsel if (myArray[counterl 111[counter2 11] -x) live++ if(myarray[counter1 +11Icounter2]X") alivo++ live; if (myArray[counterl ][counter2 1x') live++ live; if (myArray[counterl -11[counter2] -- 'x) live++ if(nyrray[counter1 -1]counter2 +11 x") alivo++ 327 live; neturn alive++ 1081.c 244:1 CRLF UTF8 C GitHub +Git (0) !update 08/03/20194 CAUsers s28281One s1C2 Atom File Edit View Selection Find Packages Help 1081.c 1084c 1025. 1015.c 1013.c include include function ther prints out an array void showArray(Char ,,myArrayl. nt nus, int cols); funct chat conts nurs of Live ne ighbours n int live Cells(char >nyarray, int canteri, nt caiinter? , int reus, int cols); 19 void updte(char. 6.orag Generation, char."new Generation, int ros, int cols); ur gaso 12 void Gane(char "current Gcneration, char "next_Gencration, int rows, int cols, int nunol Stopa): void Clearchar First Array, har *erond Array, int rows); int sain) int rons, colunns,nunofsteps, counter char* current_Ceneration 21 char" next Ganenation get inout scanf(.%d %d %d", &rows, &columns, &nunOfStep4); sperty the nopded eeiry for pous ol Lowed by a for Locp to speci/y the nocded nceory for col current Generation -allor(ssizeof(char)); for (countor-e;counterrows; countor) current Generation[counter1 -malloc(colums sizeof(char)) check for memory if there is no enough enory then exit f(current Generation- "')( print XcERRIR exit(l); specify he needed rerory for ows for next Generution 1 next Gieneratian -callec (rows, sizeaf(cha)) 42 for (counter-8: counter colunns; countora) next Generation[counter1 -calloc(colunns ,sizeof(char)) 1081.c 162:1 CRLF UTF8 GitHub +Git (0) |update 02:14 CAUsers)s2828One 1081.cC File Edit View Selection Find Packages Help sic2-Atom 1081.c 1084c 1025. 1015.c 1013.c next Generation[counter1 -calloc(colunns ,sizeof(chan)) check for memory if there is no enough nenory then exi if(next Generat ion AR1L printis ERRr exit(1); : take input for eoch row for (counter ; cunter3 live calls(current Generation, 1.1.rcus,cols)e2 )) else 1f (curent Generation( 11" live Calls(curent Generation, 1.j.roes,cols)--3) next Generationfilrin-x else if (current Genertionfilm && live cells(current Genertion, .i-os,cols>3)) .. 1081.c 162:1 CRLF UTF8 C GitHub +Git (0) |update 02:14