Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef char *cell;
- typedef cell **Board;
- #define SIZE 4
- //Function Prototypes
- Board newBoard();
- char* nullPtr();
- int main(int argc, char *argv[]) {
- int i = 0;
- int j = 0;
- Board board = newBoard();
- while (i < SIZE) {
- j = 0;
- while (j < SIZE) {
- // board[i][j] = nullPtr();
- printf("%s", board[i][j]);
- j++;
- }
- printf("\n");
- i++;
- }
- printf("%s\n", board[1][1]);
- return 0;
- }
- Board newBoard() {
- Board myBoard = (Board)malloc(sizeof(cell*) * SIZE);
- int i = 0;
- while (i < SIZE) {
- myBoard[i] =(cell*)malloc(sizeof(cell) * SIZE);
- i++;
- }
- int c = 0;
- int j = 0;
- while (c < SIZE) {
- j = 0;
- while (j < SIZE) {
- myBoard[c][j] = nullPtr();
- j++;
- }
- c++;
- }
- return myBoard;
- }
- char* nullPtr() {
- return NULL;
- }
- /*
- #define SIZE 10
- char* mallocFunction();
- int main(int argc, char* argv[]) {
- char *ptr;
- ptr = mallocFunction();
- printf("%c\n", ptr[1]);
- printf("%c\n", ptr[2]);
- printf("%c\n", *(ptr)+1);
- }
- char* mallocFunction() {
- char *array = (char*)malloc(sizeof(char) * SIZE);
- int i = 0;
- while (i < SIZE) {
- array[i] = 'e' ;
- i++;
- }
- return array;
- }
- */ /*
- typedef char *cell;
- typedef cell **Board;
- #define SIZE 4
- //Function Prototypes
- Board newBoard();
- char* nullPtr();
- int main(int argc, char *argv[]) {
- Board board = newBoard(); //returned myBoard. which board is now a char*** to myBoard
- int i = 0;
- int j = 0;
- while (i < SIZE) {
- j = 0;
- while (j < SIZE) {
- board[i][j] = nullPtr();
- printf("%s", board[i][j]); //print out elements in aray
- j++;
- }
- printf("\n"); //after printing first 4 elements keep printing in next row and so on so forth.
- i++;
- }
- // printf("%s\n",board[1][1]);
- return 0;
- }
- Board newBoard() {
- Board myBoard = (Board)malloc(sizeof(cell*) * SIZE);
- int i = 0;
- while (i < SIZE) {
- myBoard[i] =(cell*)malloc(sizeof(cell) * SIZE);
- // myBoard[i] = '1';
- i++;
- }
- return myBoard;
- }
- char* nullPtr() {
- return NULL;
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement