In order to show what is going on, I added this define,
//#define SPACE (0x20)
#define SPACE ('.')
Then I changed both instances where you printed space,
printf("%c", 0x20);
to
printf("%c", SPACE);
And then ran your program and got a single line, with some "." and some "X", but the second pass resulted in all ".",
Looks like your calculation of adjacent nodes might be wrong.
Why does your print appear wrong?
Because your first COMPASS loop uses displayBinary() 8 times,
for (i = 0; i < COMPASS; ++i) {
init32 = ((double)rand() / RAND_MAX) * 0xFFFFFFFF;
row[i] = init32;
displayBinary(row[i]);
}
While your subsequent looks use printf (rather than calling displayBinary), 8 times to only print 8 characters,
for (i = 0; i < COMPASS; ++i) {
alive += ((mask & row[i]) ? 1 : 0);
if ((alive == 2) || (alive == 3))
printf("%c", 'X');
else
printf("%c", SPACE);
}
Your HEIGHT loop does a recalculation of neighbours[], but you should be reseting row[].
I rewrote your displayBinary function, and this displays the entire row,
void displayBinary(unsigned long x) {
//do {
// printf("%c", (x & mask) ? 'X' : SPACE);
//} while ((mask >>= 1) != 0);
int bit;
int mask;
for( bit=0; bit<32; ++bit )
{
mask = 1<<bit;
printf("%c", (x & mask) ? 'X' : SPACE);
}
printf("\n");
}