Witam probuje pisac program który operowałby na tablicach struktur. Program ten to konsolowa wersja gry w życie poniżej zamieszczam kod:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define MAXSIZE 3
enum STATE {DEAD=0,ALIVE=1};
struct cell
{
enum STATE ActualState;
enum STATE NextState;
};
struct cell Array[MAXSIZE][MAXSIZE];
void SetCellTable(struct cell Array[MAXSIZE][MAXSIZE]); //ustawia losowe wartosci w komorkach
void PrnArray(struct cell Array[MAXSIZE][MAXSIZE]); //wyswietla tablice na konsoli
void ZeroArray(struct cell Array[MAXSIZE][MAXSIZE]);// zeruje elementy
int main()
{
ZeroArray(Array);
SetCellTable(Array);
PrnArray(Array);
getch();
return 0;
}
void SetCellTable(struct cell Array[MAXSIZE][MAXSIZE])
{
int i,j,rest;
srand(time(NULL));
rest=0;
for(i=0;i<MAXSIZE;i++)
for(j=0;j<MAXSIZE;j++)
{
rest=rand()%2;
if(rest==0)
Array[i][j].ActualState=DEAD;
else if(rest==1)
Array[i][j].ActualState=ALIVE;
}
}
void PrnArray(struct cell Array[MAXSIZE][MAXSIZE])
{
int i,j;
for(i=0;i<MAXSIZE;i++)
{
for(j=0;j<MAXSIZE;j++)
printf(" %d ",Array[i][j].NextState);
printf("\n");
}
}
void ZeroArray(struct cell Array[MAXSIZE][MAXSIZE])
{
int i,j;
for(i=0;i<MAXSIZE;i++)
for(j=0;j<MAXSIZE;j++)
{
Array[i][j].ActualState=DEAD;
Array[i][j].NextState=DEAD;
}
}
Funkcja wyświetlająca tablice produkuje błędne wyniki nie wiem co jest nie tak
Mam jeszcze pytanie odnośnie tego, dlaczego w funkcjach operujących na strukturach muszę podawa rozmiar tablicy struktur,przy funkcjach operujących na obiektach typu int char itp nie trzeba dodawac rozmiaru tablicy.