I'm getting the same output as the other site.

---------------
---------------
---------------
-------*-*-----
-------*-*-----
-------***-----
---------------
---------------
---------------
---------------
Generation 1:

---------------
---------------
---------------
---------------
------**-**----
-------*-*-----
--------*------
---------------
---------------
---------------
Generation 2:

---------------
---------------
---------------
---------------
------**-**----
------**-**----
--------*------
---------------
---------------
---------------
Generation 3:

---------------
---------------
---------------
---------------
------**-**----
------*---*----
-------***-----
---------------
---------------
---------------

Hmmm what in the world... Well the code that you posted to resync with mine did not have the <= in the occ function... So I changed that. Can you copy the exact code that you have that made your last post? That is weird...

Sorry. Don't know how that happened.

#include <stdio.h>

#define SIZE 10
#define SIZE2 15
#define max(A,B) ( (A) > (B) ? (A):(B))
#define min(A,B) ( (A) < (B) ? (A):(B))

void initconfig(int [][SIZE2], int, int, int*);
int occ(int [][SIZE2], int, int);
void generate(int [][SIZE2], int, int);
void printgrid(int [][SIZE2], int, int );

int main ()
{

   int coordArray[SIZE][SIZE2] = {0}, x = 0, y = 0,
   i, generations = 0;

   initconfig(coordArray, x, y, &generations);

   puts("Initial State");
   printgrid(coordArray, SIZE, SIZE2);
   for ( i = 0; i < generations; ++i )
   {
      printf("Generation %d:\n", i + 1);
      generate(coordArray, SIZE, SIZE2);
      printgrid(coordArray, SIZE, SIZE2);
   }

   return 0;

}

void initconfig(int coordArray[][SIZE2], int x, int y, int *generations)
{
   printf("\nEnter the number of generations: ");
   scanf("%d", generations);

   printf("\nEnter coordinates: ");
   scanf("%d%d", &x, &y);

   while ( x != -1 )
   {

      if ( x<1 || x>10 || y<1 || y>15 )
         printf("\nInvalid input.");
      else
         coordArray[x-1][y-1] = 1;

      printf("\nEnter coordinates: ");
      scanf("%d%d", &x, &y);
   }
   putchar('\n');
}

void generate(int coordArray[][SIZE2], int row, int col)
{
   int tempArray[SIZE][SIZE2] = {0}, i=0, j=0;


   for ( i=0; i < row; i++ )
   {
      for ( j=0; j < col; j++ )
      {
         int count = occ(coordArray, i, j);
         if ( coordArray[i][j] == 1 )
         {
            if ( count == 2 || count == 3 )
            {
               tempArray[i][j] = 1;
            }
            else
            {
               tempArray[i][j] = 0;
            }
         }

         if ( coordArray[i][j] == 0 )
         {
            if ( count == 3 )
            {
               tempArray[i][j] = 1;
            }
            else
            {
               tempArray[i][j] = 0;
            }
         }
      }
   }

   for ( i=0; i< row; i++ )
   {
      for ( j=0; j < col; j++ )
      {
         coordArray[i][j] = tempArray[i][j];
      }
   }
}


int occ( int coordArray[][SIZE2], int x, int y )
{
   int neighbourCount = 0, i, j;
   for ( i = max( 0, x - 1 ) ; i <= min( SIZE - 1, x + 1 ); i++ )
   {
      for ( j = max( 0, y - 1 ) ; j <= min( SIZE2 - 1, y + 1 ); j++ )
      {
         if ( ( x == i ) && ( y == j ) )
         {
            continue;
         }
         if ( coordArray[ i ][ j ] == 1 )
         {
            neighbourCount++ ;
         }
      }
   }
   return neighbourCount;
}

void printgrid(int coordArray[][SIZE2], int row, int col)
{
   int i, j;

   for ( i=0; i < row; i++ )
   {
      for ( j=0; j < col; j++ )
      {
         if ( coordArray[i][j] == 1 )
         {
            putchar('*');
         }
         else
            putchar('-');
      }
      putchar('\n');
   }
   putchar('\n');
}

/* my input
10
4 8
4 10
5 8
5 10
6 8
6 9
6 10
-1 -1
*/

/* my output
C:\Test>test < file.txt

Enter the number of generations: 
Enter coordinates: 
Enter coordinates: 
Enter coordinates: 
Enter coordinates: 
Enter coordinates: 
Enter coordinates: 
Enter coordinates: 
Enter coordinates: 
Initial State
---------------
---------------
---------------
-------*-*-----
-------*-*-----
-------***-----
---------------
---------------
---------------
---------------

Generation 1:
---------------
---------------
---------------
---------------
------**-**----
-------*-*-----
--------*------
---------------
---------------
---------------

Generation 2:
---------------
---------------
---------------
---------------
------**-**----
------**-**----
--------*------
---------------
---------------
---------------

Generation 3:
---------------
---------------
---------------
---------------
------**-**----
------*---*----
-------***-----
---------------
---------------
---------------

Generation 4:
---------------
---------------
---------------
---------------
------**-**----
------*---*----
-------***-----
--------*------
---------------
---------------

Generation 5:
---------------
---------------
---------------
---------------
------**-**----
------*---*----
-------***-----
-------***-----
---------------
---------------

Generation 6:
---------------
---------------
---------------
---------------
------**-**----
------*---*----
------*---*----
-------*-*-----
--------*------
---------------

Generation 7:
---------------
---------------
---------------
---------------
------**-**----
-----**---**---
------**-**----
-------***-----
--------*------
---------------

Generation 8:
---------------
---------------
---------------
---------------
-----***-***---
-----*-----*---
-----*-----*---
------*---*----
-------***-----
---------------

Generation 9:
---------------
---------------
---------------
------*---*----
-----**---**---
----**-----**--
-----**---**---
------*****----
-------***-----
--------*------

Generation 10:
---------------
---------------
---------------
-----**---**---
----*-*---*-*--
----*-------*--
----*---*---*--
-----*-----*---
------*---*----
-------***-----
*/

This one may have gone further than you needed.

OK! That works! Thank you sooo much! You guys here are awesome, and I'm sorry for prolonging this with my lack of knowledge! This is solved! Now for a much needed meal. Thank you so much again!

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.