Aurox_

cringe

Jan 11th, 2024 (edited)
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. #define STRLEN      1024
  6. #define MAX_ITERAZIONI  30
  7. #define S_MIN       2
  8. #define S_MAX       3
  9. #define B_MIN       3
  10. #define B_MAX       3
  11. #define ALIVE       1
  12. #define DEAD        0
  13.  
  14. typedef int*    pint;
  15. typedef int**   ppint;
  16. typedef char*   pchar;
  17.  
  18. int get_int(pchar q)
  19. {
  20.     char input[STRLEN];
  21.     printf("%s: ",q);
  22.     scanf("%s",input);
  23.     return atoi(input);
  24. }
  25.  
  26. int frame(ppint ppcasella, int nr, int nc) {
  27.    
  28. }
  29.  
  30. int print_tab(ppint ppcasella, int nr, int nc) {
  31.     ppint pprmax;
  32.     pint pcmax;
  33.     for (pprmax=ppcasella+nr;ppcasella<pprmax;ppcasella++) {
  34.         for (pcmax=(*ppcasella)+nc;(*ppcasella)<pcmax;(*ppcasella)++) {
  35.             if (**ppcasella) printf("# ");
  36.             else printf("_ ");
  37.         }
  38.     printf("\n");
  39.     }
  40.     return 1;
  41. }
  42.  
  43. int main(void) {
  44.     int nr,nc,ntot,i,j,life,iter,check;
  45.     ppint ppcasella,ppcasellaswap,pptemp;
  46.     srand(time(NULL));
  47.  
  48.     while ((nr=get_int("Numero di righe"))<=0) {
  49.         printf("Per favore, inserisci un numero positivo.\n");
  50.     }
  51.     while ((nc=get_int("Numero di colonne"))<=0) {
  52.         printf("Per favore, inserisci un numero positivo.\n");
  53.     }
  54.     check=1;
  55.     do {
  56.         life=get_int("Densita' di celle vive [0:100]");
  57.         if ((life<0)||(life>100)) printf("Per favore, inserisci un numero nell'intervallo [0,100].\n");
  58.         else check=0;
  59.     } while (check);
  60.     //printf("Ho acquisito i seguenti valori:\nRighe: %d,\nColonne: %d,\nTotale caselle: %d,\nDensita': %d.\n",nr,nc,(ntot=(nc*nr)),life);
  61.     printf("Uno");
  62.     if((ppcasella=(ppint)malloc(sizeof(pint)*nr))==NULL) goto err_mem;
  63.     printf("due");
  64.     //if((ppcasellaswap=(ppint)malloc(sizeof(pint)*nr))==NULL) goto err_mem;
  65.     for (i=0;i<nc;i++) {
  66.         printf("(%d)",i);
  67.         if((ppcasella[i]=(pint)malloc(sizeof(int)*nc))==NULL) goto err_mem;
  68.         //if((ppcasellaswap[i]=(pint)malloc(sizeof(int)*nc))==NULL) goto err_mem;
  69.     }
  70.  
  71.     printf("stocaszozo");
  72.     for(i=0;i<nr;i++) {
  73.        
  74.         for (j=0;j<nc;j++) {
  75.            
  76.             if (((((float)rand())/RAND_MAX)*100)<=life) ppcasella[i][j]=1;
  77.             else ppcasella[i][j]=0;  
  78.         }
  79.     }
  80.  
  81.  
  82.     for (iter=0;iter<MAX_ITERAZIONI;iter++) {
  83.         printf("%d\n",iter);
  84.         for (i=0;i<nr;i++) {
  85.             for (j=0;j<nc;j++) {
  86.                 switch (ppcasella[i][j]) {
  87.                     case ALIVE:
  88.  
  89.                         break;
  90.                     case DEAD:
  91.                 }
  92.             }
  93.  
  94.         }
  95.     }
  96.  
  97.     print_tab(ppcasella,nr,nc);
  98.     printf("\n");
  99.  
  100.     return EXIT_SUCCESS;
  101.     err_mem:
  102.     printf("Errore memoria\n");
  103.     return EXIT_FAILURE;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment