Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.29 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define SOME_SIZE 10
  4.  
  5. #define BOARDSIZE 6
  6. int main()
  7. {
  8.     printf("Hello World\n");
  9.    
  10.     //malloc a pointer to an array of arrays of strings of size 4
  11.     char *** myBoard = (char ***)malloc(BOARDSIZE * sizeof(char **));
  12.     int i = 0;
  13.     int j = 0;
  14.     char str[] = "hi";
  15.    
  16.     while (i < BOARDSIZE) {
  17.         j = 0;
  18.         //malloc a pointer to an array of strings
  19.         myBoard[i] =  (char **)malloc(BOARDSIZE * sizeof(char *));
  20.         while (j < BOARDSIZE ) {
  21.             myBoard[i][j] = NULL;
  22.             j++;
  23.         }
  24.         i++;
  25.     }
  26.    
  27.     i = j = 0;
  28.  
  29.     //this is what you have to copy into populate
  30.     //and instead of putting in some string
  31.     //you have to do that conversion
  32.     while (i < BOARDSIZE) {
  33.         j = 0;
  34.         while (j < BOARDSIZE ) {
  35.             //malloc each array index to a string
  36.             myBoard[i][j] = (char*)malloc(SOME_SIZE * sizeof(char));
  37.             myBoard[i][j] = str;
  38.             j++;
  39.         }
  40.         i++;
  41.     }
  42.    
  43.    
  44.     i = j = 0;
  45.    
  46.     while (i < BOARDSIZE) {
  47.         j = 0;
  48.         while (j < BOARDSIZE ) {
  49.             printf("%s ",  myBoard[i][j] );
  50.             j++;
  51.         }
  52.         printf("\n");
  53.         i++;
  54.     }
  55.    
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement