Hi, I am having trouble whit writing a code for game of life..
This is what I came up with;

#include <stdio.h>
#include <stdlib.h>

   void header(void);
   void survivalRule(char [][20], int, int);
   void birthRule(char [][20], int, int);
   void deathRule(char [][20], int, int);
       
    int main(void)
   {
      char Life[20][20];
      int orgs, gens;
      int i, a, b, row, col;
      int count = 0;
      int x = 19;
      int y = 19;
      char ans;
       
      header();
  
      do{
         printf("\nPlease enter the number of organisms you would like to live in the first generation: ");
         scanf("%i", &orgs);
      
         srand( (unsigned)time( NULL ) );
              
         for(i = 0; i<orgs; i++)
         {
            row = rand();
            row %= 20;
            col = rand();
            col %= 20;
            Life[row][col] == '*';
         }
        
         for(row = 0; row<20; row++)
         {
            for(col = 0; col<20; col++)
            {
               if(Life[row][col] != '*')
                   Life[row][col] == ' ';
            }
         }
              
         printf("\nNow enter the number of generations you would like to simulate: ");
         scanf("%i", &gens);
              
         for(row = 0; row<20; row++)
         {
              for(col = 0; col<20; col++)
              {
                  printf("%s", Life[row][col]);
              }
              puts(" ");
          }
            
         do{                
            birthRule(Life, x, y);
            survivalRule(Life, x, y);
            deathRule(Life, x, y);
                for(row = 0; row<20; row++)
             {
                  for(col = 0; col<20; col++)
                  {
                      printf("%s", Life[row][col]);
                  }
                  puts(" ");
             }
            count++;
         }while(count<gens);
          
         printf("Would you like to simulate another generation? y or n:\n");
          
         scanf("%c", &ans);
              
      }while( ans != 'n' && ans != 'N');
       
      return 0;
   }
            
                
    void header(void) /*function for program header*/
   {
      printf("\n\t..Welcome to the Game of Life..\n");
      printf("Follow the instructions to start your own simulation of life!\n\n");
   }
    
    void survivalRule(char Life[][20], int x, int y)
   {
      int row, col;
      int neighbors = 0;
      for(row = 1; row<19; row++)
      {
         for(col = 1; col<19; col++)
         {
            if(Life[row][col] == '*')
            {
               if(Life[row - 1][col - 1] == '*')
                  ++neighbors;
               if(Life[row - 1][col] == '*')
                  ++neighbors;
               if(Life[row - 1][col + 1] == '*')
                  ++neighbors;
               if(Life[row][col - 1] == '*')
                  ++neighbors;
               if(Life[row][col + 1] == '*')
                  ++neighbors;
               if(Life[row + 1][col - 1] == '*')
                  ++neighbors;
               if(Life[row + 1][col] == '*')
                  ++neighbors;
               if(Life[row + 1][col + 1] == '*')
                  ++neighbors;
               if(neighbors == 2 || neighbors == 3)
               {
                  Life[row][col] == '*';
               }
            }
         }
      }
      return;
   }
    
    void birthRule(char Life[][20], int x, int y)
   {
      int row, col;
      int neighbors = 0;
      for(row = 1; row<19; row++)
      {
         for(col = 1; col<19; col++)
         {
            if(&Life[row][col]== " ")
            {
               if(Life[row - 1][col - 1] == '*')
                  neighbors++;
               if(Life[row - 1][col] == '*')
                  neighbors++;
               if(Life[row - 1][col + 1] == '*')
                  neighbors++;
               if(Life[row][col - 1] == '*')
                  neighbors++;
               if(Life[row][col + 1] == '*')
                  neighbors++;
               if(Life[row + 1][col - 1] == '*')
                  neighbors++;
               if(Life[row + 1][col] == '*')
                  neighbors++;
               if(Life[row + 1][col + 1] == '*')
                  neighbors++;
               if(neighbors == 3)
               {
                   Life[row][col] == '*';
               }
            }
         }
      }
  
      return;
   }
    
    void deathRule(char Life[][20], int x, int y)
   {
      int row, col;
      int neighbors = 0;
      for(row = 1; row<19; row++)
      {
         for(col = 1; col<19; col++)
         {
            if(Life[row][col] == '*')
            {
               if(Life[row - 1][col - 1] == '*')
                  neighbors++;
               if(Life[row - 1][col] == '*')
                  neighbors++;
               if(Life[row - 1][col + 1] == '*')
                  neighbors++;
               if(Life[row][col - 1] == '*')
                  neighbors++;
               if(Life[row][col + 1] == '*')
                  neighbors++;
               if(Life[row + 1][col - 1] == '*')
                  neighbors++;
               if(Life[row + 1][col] == '*')
                  neighbors++;
               if(Life[row + 1][col + 1] == '*')
                  neighbors++;
               if(neighbors < 2 || neighbors > 4)
               {
                  Life[row][col] == ' ';
               }
            }
         }
      }
      return;
   }

but it needs to be in this skeleton;

#include <stdio.h>
#include <stdlib.h>

#define MAX_ROWS 21
#define MAX_COLUMNS 44  

#define FALSE 0
#define TRUE 1

#define DELAY 100000000


/* main functions */
void PrintWorld(char [][], int, int);
void ClearWorld(char [][], int, int);
void CopyWorld(char [][], char [][], int, int);
void NextGeneration(char [][], char [][], int, int); 
void Animate(int,int);
int LiveCell(char [][], int, int);

/* neighboring cells in major wind directions */
int North(char [][], int, int);
int East(char [][], int, int);
int South(char [][], int, int);
int West(char [][], int, int);

/* neighboring cells in minor wind directions */
int NorthEast(char [][], int, int);
int SouthEast(char [][], int, int);
int SouthWest(char [][], int, int);
int NorthWest(char [][], int, int);


main()
{
        char emptyWorld[MAX_ROWS][MAX_COLUMNS] = {"!------------------------------------------!",
                                                  "!                                          !",
                                                  "!                                          !",   
                                                  "!                                          !",
                                                  "!                                          !",
                                                  "!                                          !",
                                                  "!                                          !",
                                                  "!                                          !",
                                                  "!                                          !",
                                                  "!                                          !",
                                                  "!                                          !",
                                                  "!                                          !",
                                                  "!                                          !",
                                                  "!                                          !",
                                                  "!                                          !",
                                                  "!                                          !",
                                                  "!                                          !",
                                                  "!                                          !",
                                                  "!                                          !",
                                                  "!                                          !",
                                                  "!------------------------------------------!"};
                                           
                                           
        char stableWorld[MAX_ROWS][MAX_COLUMNS] = {"!------------------------------------------!",
                                                   "!                                          !",
                                                   "!       xx xx                              !",   
                                                   "!        x x                               !",
                                                   "!        x x            xx                 !",
                                                   "!       xx xx           xx                 !",
                                                   "!                                          !",
                                                   "!                                          !",
                                                   "!                                          !",
                                                   "!       xxxx             x                 !",
                                                   "!                        xx                !",
                                                   "!                         x                !",
                                                   "!                                          !",
                                                   "!                                          !",
                                                   "!                                          !",
                                                   "!                                          !",
                                                   "!            x                             !",
                                                   "!            xxx                           !",
                                                   "!                                          !",
                                                   "!                                          !",
                                                   "!------------------------------------------!"};
         
        
        
        char oscillatingWorld[MAX_ROWS][MAX_COLUMNS] = {"!------------------------------------------!",
                                                        "!                                          !",
                                                        "!                                          !",   
                                                        "!                                          !",
                                                        "!                                          !",
                                                        "!       xx     xx                          !",
                                                        "!        xx   xx               xxx         !",
                                                        "!     x  x x x x  x                        !",
                                                        "!     xxx xx xx xxx                        !",
                                                        "!      x x x x x x                         !",
                                                        "!       xxx   xxx                          !",
                                                        "!                                          !",
                                                        "!       xxx   xxx                          !",
                                                        "!      x x x x x x               x         !",
                                                        "!     xxx xx xx xxx              x         !",
                                                        "!     x  x x x x  x              x         !",
                                                        "!        xx   xx                           !",
                                                        "!       xx     xx                          !",                                 
                                                        "!                                          !",
                                                        "!                                          !",
                                                        "!------------------------------------------!"};
                                                        
      
      
         char spaceShipWorld[MAX_ROWS][MAX_COLUMNS] = {"!------------------------------------------!",
                                                      "!                                          !",
                                                      "!     x                                    !",   
                                                      "!      x                                   !",
                                                      "!    xxx                                   !",
                                                      "!                                          !",
                                                      "!                                          !",
                                                      "!                                          !",
                                                      "!                                          !",
                                                      "!                                          !",
                                                      "!                                          !",
                                                      "!                                          !",
                                                      "!                                          !",
                                                      "!                                          !",
                                                      "!                                          !",
                                                      "!                                          !",
                                                      "!           x                              !",
                                                      "!          x                               !",
                                                      "!          xxx                             !",
                                                      "!                                          !",
                                                      "!------------------------------------------!"};
                                                      
                                                      
                                                      
        char world [MAX_ROWS][MAX_COLUMNS], newWorld [MAX_ROWS][MAX_COLUMNS];       
        int tick;
        
      
}

/* print the grid of the world including the boundaries */
void PrintWorld(char world[][MAX_COLUMNS], int m, int n)
{
        
}


/* clear all cells of the world. CAUTION: do not overwrite the array elements along the margins */ 
void ClearWorld(char world[][MAX_COLUMNS], int m, int n)
{
       
}


/* make a copy of the world */
void CopyWorld(char world[][MAX_COLUMNS], char copyWorld[][MAX_COLUMNS], int m, int n)
{
        
}


/* compute the next generation of the world */
void NextGeneration(char oldWorld[][MAX_COLUMNS], char newWorld[][MAX_COLUMNS], int m, int n)
{
        
}


/* insert sufficient printf("\n") statements to display the world in the same place as the one
   before and delay printing the next world sufficiently so that it looks like a movie */
void Animate(int tick, int delay)
{
             
}


/* return 1 if a cell at (x, y) is alive and 0 otherwise */
int LiveCell(char world[][MAX_COLUMNS], int i, int j)
{
       
}


/* return 1 if a cell North of (x, y) is alive and 0 otherwise 
   special care must be taken to find the neighbors of cells 
   along the upper boundary of the world                        */                             
int North(char world[][MAX_COLUMNS], int row, int column)
{
       
}


/* return 1 if a cell Northeast of (x, y) is alive and 0 otherwise  
   special care must be taken to find the neighbors of cells 
   along the upper and right boundaries of the world              */  
int NorthEast(char world[][MAX_COLUMNS], int row, int column)
{
        
}


/* return 1 if a cell East of (x, y) is alive and 0 otherwise  
   special care must be taken to find the neighbors of cells 
   along the right boundary of the world                        */  
int East(char world[][MAX_COLUMNS], int row, int column)
{
        
}


/* return 1 if a cell Southeast of (x, y) is alive and 0 otherwise  
   special care must be taken to find the neighbors of cells 
   along the left and lower boundaries of the world             */  
int SouthEast(char world[][MAX_COLUMNS], int row, int column)
{
       
}



/* return 1 if a cell South of (x, y) is alive and 0 otherwise  
   special care must be taken to find the neighbors of cells 
   along the lower boundary of the world                        */  
int South(char world[][MAX_COLUMNS], int row, int column)
{
        
}


/* return 1 if a cell Southwest of (x, y) is alive and 0 otherwise  
   special care must be taken to find the neighbors of cells 
   along the lower and left boundaries of the world             */  
int SouthWest(char world[][MAX_COLUMNS], int row, int column)
{
          
}


/* return 1 if a cell West of (x, y) is alive and 0 otherwise  
   special care must be taken to find the neighbors of cells 
   along the left boundary of the world                        */  
int West(char world [][MAX_COLUMNS], int row, int column)
{
        
}


/* return 1 if a cell Northwest of (x, y) is alive and 0 otherwise  
   special care must be taken to find the neighbors of cells 
   along the left and upper boundaries of the world             */  
int NorthWest(char world [][MAX_COLUMNS], int row, int column)
{
        
}

Can anyone help me pleaseeee

homework?

game of life was the homework but the skeleton came after, and I have to used the skeleton...

So i did the homework part but this was the skeleton given for the "perfect" solution.. just want to know it..

So what's the problem?

For example, implement LiveCell() by calling a bunch of North() etc.

the problem is I cannot adjust the program I wrote to the skeleton...

Huh?

if(Life[row - 1][col - 1] == '*')
is called "North" (or something)

that would be northwest yeah thanks got it!

commented: :) +32
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.