Browse Source

create grid with 2d array of characters, make template

2much 2 years ago
parent
commit
0d72fcfb57
3 changed files with 57 additions and 13 deletions
  1. 30 0
      gridv1.c
  2. BIN
      tannebaumv3
  3. 27 13
      tannebaumv3.c

+ 30 - 0
gridv1.c

@@ -0,0 +1,30 @@
+#include <stdio.h>
+ 
+#define GRID_SIZE 9
+  
+void initGrid(char grid[][GRID_SIZE]);
+void printGrid(char grid[][GRID_SIZE]);
+ 
+int main(void) {
+    char grid[GRID_SIZE][GRID_SIZE];
+ 
+    initGrid(grid);
+    printGrid(grid);
+ 
+    return 0;
+}
+ 
+void initGrid(char grid[][GRID_SIZE]) {
+    for (int x = 0; x < GRID_SIZE; x++)
+        for (int y = 0; y < GRID_SIZE; y++)
+            grid[x][y] = ' ';
+    // or memset(grid, ' ', GRID_SIZE * GRID_SIZE);
+}
+ 
+void printGrid(char grid[][GRID_SIZE]) {
+    for (int x = 0; x < GRID_SIZE; x++) {
+        for (int y = 0; y < GRID_SIZE; y++)
+            printf("[%c]", grid[x][y]);
+        printf("\n");
+    }
+}

BIN
tannebaumv3


+ 27 - 13
tannebaumv3.c

@@ -1,16 +1,30 @@
 #include <stdio.h>
-
-void main() {
-    char display[2][3] = {
-	{'_','_'},
-	{'|','|','|'}
-    };
-    
-    int i, j;
-    for (i = 0; i < 2; i++) {
-        for (j = 0; j > 3; j++) {
-	    printf("%d ", display[i][j]);
-	}
+ 
+#define GRID_SIZE 9
+  
+void initGrid(char grid[][GRID_SIZE]);
+void printGrid(char grid[][GRID_SIZE]);
+ 
+int main(void) {
+    char grid[GRID_SIZE][GRID_SIZE];
+ 
+    initGrid(grid);
+    printGrid(grid);
+ 
+    return 0;
+}
+ 
+void initGrid(char grid[][GRID_SIZE]) {
+    for (int x = 0; x < GRID_SIZE; x++)
+        for (int y = 0; y < GRID_SIZE; y++)
+            grid[x][y] = ' ';
+    // or memset(grid, ' ', GRID_SIZE * GRID_SIZE);
+}
+ 
+void printGrid(char grid[][GRID_SIZE]) {
+    for (int x = 0; x < GRID_SIZE; x++) {
+        for (int y = 0; y < GRID_SIZE; y++)
+            printf("[%c]", grid[x][y]);
+        printf("\n");
     }
-
 }