Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define SOME_SIZE 10
- #define BOARDSIZE 6
- int main()
- {
- printf("Hello World\n");
- //malloc a pointer to an array of arrays of strings of size 4
- char *** myBoard = (char ***)malloc(BOARDSIZE * sizeof(char **));
- int i = 0;
- int j = 0;
- char str[] = "hi";
- while (i < BOARDSIZE) {
- j = 0;
- //malloc a pointer to an array of strings
- myBoard[i] = (char **)malloc(BOARDSIZE * sizeof(char *));
- while (j < BOARDSIZE ) {
- myBoard[i][j] = NULL;
- j++;
- }
- i++;
- }
- i = j = 0;
- //this is what you have to copy into populate
- //and instead of putting in some string
- //you have to do that conversion
- while (i < BOARDSIZE) {
- j = 0;
- while (j < BOARDSIZE ) {
- //malloc each array index to a string
- myBoard[i][j] = (char*)malloc(SOME_SIZE * sizeof(char));
- myBoard[i][j] = str;
- j++;
- }
- i++;
- }
- i = j = 0;
- while (i < BOARDSIZE) {
- j = 0;
- while (j < BOARDSIZE ) {
- printf("%s ", myBoard[i][j] );
- j++;
- }
- printf("\n");
- i++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement