Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define STRLEN 1024
- #define MAX_ITERAZIONI 30
- #define S_MIN 2
- #define S_MAX 3
- #define B_MIN 3
- #define B_MAX 3
- #define ALIVE 1
- #define DEAD 0
- typedef int* pint;
- typedef int** ppint;
- typedef char* pchar;
- int get_int(pchar q)
- {
- char input[STRLEN];
- printf("%s: ",q);
- scanf("%s",input);
- return atoi(input);
- }
- int frame(ppint ppcasella, int nr, int nc) {
- }
- int print_tab(ppint ppcasella, int nr, int nc) {
- ppint pprmax;
- pint pcmax;
- for (pprmax=ppcasella+nr;ppcasella<pprmax;ppcasella++) {
- for (pcmax=(*ppcasella)+nc;(*ppcasella)<pcmax;(*ppcasella)++) {
- if (**ppcasella) printf("# ");
- else printf("_ ");
- }
- printf("\n");
- }
- return 1;
- }
- int main(void) {
- int nr,nc,ntot,i,j,life,iter,check;
- ppint ppcasella,ppcasellaswap,pptemp;
- srand(time(NULL));
- while ((nr=get_int("Numero di righe"))<=0) {
- printf("Per favore, inserisci un numero positivo.\n");
- }
- while ((nc=get_int("Numero di colonne"))<=0) {
- printf("Per favore, inserisci un numero positivo.\n");
- }
- check=1;
- do {
- life=get_int("Densita' di celle vive [0:100]");
- if ((life<0)||(life>100)) printf("Per favore, inserisci un numero nell'intervallo [0,100].\n");
- else check=0;
- } while (check);
- //printf("Ho acquisito i seguenti valori:\nRighe: %d,\nColonne: %d,\nTotale caselle: %d,\nDensita': %d.\n",nr,nc,(ntot=(nc*nr)),life);
- printf("Uno");
- if((ppcasella=(ppint)malloc(sizeof(pint)*nr))==NULL) goto err_mem;
- printf("due");
- //if((ppcasellaswap=(ppint)malloc(sizeof(pint)*nr))==NULL) goto err_mem;
- for (i=0;i<nc;i++) {
- printf("(%d)",i);
- if((ppcasella[i]=(pint)malloc(sizeof(int)*nc))==NULL) goto err_mem;
- //if((ppcasellaswap[i]=(pint)malloc(sizeof(int)*nc))==NULL) goto err_mem;
- }
- printf("stocaszozo");
- for(i=0;i<nr;i++) {
- for (j=0;j<nc;j++) {
- if (((((float)rand())/RAND_MAX)*100)<=life) ppcasella[i][j]=1;
- else ppcasella[i][j]=0;
- }
- }
- for (iter=0;iter<MAX_ITERAZIONI;iter++) {
- printf("%d\n",iter);
- for (i=0;i<nr;i++) {
- for (j=0;j<nc;j++) {
- switch (ppcasella[i][j]) {
- case ALIVE:
- break;
- case DEAD:
- }
- }
- }
- }
- print_tab(ppcasella,nr,nc);
- printf("\n");
- return EXIT_SUCCESS;
- err_mem:
- printf("Errore memoria\n");
- return EXIT_FAILURE;
- }
Advertisement
Add Comment
Please, Sign In to add comment