Advertisement
Guest User

rk.h

a guest
Apr 6th, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <X11/Xlib.h>
  4.  
  5. static Window** box;     /* box (NYxNX) window array address */
  6. static Window* row;      /* NY row window  box containe array  */
  7. static unsigned NX=4;   /* Default Boxes' number in each row */
  8. static unsigned NY=2;    /* Default Row's number in game desk */
  9.  
  10. /* dynamic memory allocation for all game desk array */
  11. int alloc() {
  12.     void* r;                /* row array pointer */
  13.     void** b;               /* box array pointer */
  14.     int i;                  /* row array index */
  15.     r = calloc(NY, sizeof(unsigned long));
  16.     b = calloc(NY, sizeof(void*));
  17.     for(i=0; i < NY; i++) {
  18.         b[i] = calloc(NX,  sizeof(unsigned long));
  19.     }
  20.     row = (Window* ) r;
  21.     box = (Window**) b;
  22.     return(0);
  23. }
  24.  
  25. /* free allocated memory */
  26. int dealloc(Window** b, Window* r) {
  27.     int i;   /* row index */
  28.     for(i=0; i < NY; i++) {
  29.         free(b[i]);
  30.     }
  31.     free(b); free(r);
  32.     return(0);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement