SHARE
TWEET

Untitled

a guest Apr 21st, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5.  
  6.  
  7. typedef char *cell;
  8. typedef cell **Board;
  9.  
  10. #define SIZE 4
  11. //Function Prototypes
  12. Board newBoard();
  13. char* nullPtr();
  14.  
  15.  
  16. int main(int argc, char *argv[]) {
  17.  
  18.     int i = 0;
  19.     int j = 0;
  20.     Board board = newBoard();    
  21.        while (i < SIZE) {
  22.         j = 0;
  23.         while (j < SIZE) {
  24.  
  25.            // board[i][j] = nullPtr();
  26.             printf("%s", board[i][j]);      
  27.             j++;
  28.         }
  29.         printf("\n");                      
  30.         i++;    
  31.     }
  32.     printf("%s\n", board[1][1]);
  33.     return 0;
  34. }
  35.  
  36.  
  37. Board newBoard() {
  38.  
  39.     Board myBoard = (Board)malloc(sizeof(cell*) * SIZE);
  40.     int i = 0;
  41.     while (i < SIZE) {      
  42.         myBoard[i] =(cell*)malloc(sizeof(cell) * SIZE);                            
  43.         i++;
  44.     }
  45.     int c = 0;
  46.     int j = 0;
  47.     while (c < SIZE) {
  48.         j = 0;
  49.         while (j < SIZE) {
  50.             myBoard[c][j] = nullPtr();  
  51.             j++;
  52.         }                    
  53.         c++;    
  54.     }
  55.        return myBoard;
  56. }
  57.  
  58. char* nullPtr() {
  59.    
  60.    
  61.     return NULL;
  62.  
  63. }
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98. /*
  99. #define SIZE 10
  100. char* mallocFunction();
  101. int main(int argc, char* argv[]) {
  102.  
  103.     char *ptr;
  104.     ptr = mallocFunction();
  105.     printf("%c\n", ptr[1]);
  106.     printf("%c\n", ptr[2]);
  107.    
  108.     printf("%c\n", *(ptr)+1);
  109.    
  110.  
  111. }
  112.  
  113. char* mallocFunction() {
  114.     char *array = (char*)malloc(sizeof(char) * SIZE);
  115.     int i = 0;
  116.     while (i < SIZE) {
  117.        
  118.         array[i] = 'e' ;
  119.         i++;
  120.        
  121.     }
  122.    
  123. return array;
  124. }
  125. */ /*
  126. typedef char *cell;
  127. typedef cell **Board;
  128.  
  129. #define SIZE 4
  130. //Function Prototypes
  131. Board newBoard();
  132. char* nullPtr();
  133.  
  134.  
  135. int main(int argc, char *argv[]) {
  136.  
  137.    
  138.     Board board = newBoard();       //returned myBoard. which board is now a char*** to myBoard
  139.     int i = 0;
  140.     int j = 0;
  141.     while (i < SIZE) {
  142.         j = 0;
  143.         while (j < SIZE) {
  144.             board[i][j] = nullPtr();
  145.             printf("%s", board[i][j]);      //print out elements in aray
  146.             j++;
  147.         }
  148.         printf("\n");                       //after printing first 4 elements keep printing in next row and so on so forth.
  149.         i++;    
  150.     }
  151. //  printf("%s\n",board[1][1]);
  152.    
  153.     return 0;
  154. }
  155.  
  156.  
  157. Board newBoard() {
  158.  
  159.     Board myBoard = (Board)malloc(sizeof(cell*) * SIZE);
  160.     int i = 0;
  161.     while (i < SIZE) {      
  162.         myBoard[i] =(cell*)malloc(sizeof(cell) * SIZE);                        
  163.  
  164.       //  myBoard[i] = '1';
  165.         i++;
  166.     }
  167.     return myBoard;
  168. }
  169.  
  170. char* nullPtr() {
  171.    
  172.    
  173.     return NULL;
  174.  
  175. }
  176.  
  177.  
  178.  
  179. */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top