9511_workbook

solved exercises from algorithms & programming I (9511) prof. Cardozo
Index Commits Files Refs README
commit dd180ce0de9cd17c9506250a7e2d546ecc6bf0b3
parent 939fcdc0a333be9a3613aae877777459aaf494d2
Author: klewer-martin <martin.cachari@gmail.com>
Date:   Wed, 26 May 2021 23:56:46 -0300

Update: added guia04/ex06.c

Diffstat:
MMakefile | 3++-
Aguia04/ex06.c | 30++++++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
@@ -1,2 +1,3 @@
 clean:
-    rm ./**/*.o
+    find . -name a.out -type f -delete
+    find . -name \*.o -type f -delete
diff --git a/guia04/ex06.c b/guia04/ex06.c
@@ -0,0 +1,30 @@
+/*    G04E06 - Print elements of a 2D array using pointer    
+ *    by Martin J. Kloeckner    
+ *    github.com/klewer-martin    */
+
+#include <stdio.h>
+
+int main (void)
+{
+    int *dos_ptr; 
+    int (*ptr2vector)[4]; 
+
+    int dos_vector[3][4] = { { 1, 2, 3, 4 }, 
+                             { 5, 6, 7, 8 },
+                             { 9,10,11,12 } }; 
+
+    dos_ptr = dos_vector[0];
+    for(size_t i = 0; i < 3 * 4; i++)
+        printf("dos_vector[%ld][%ld]: %2d\n", i / 4, i % 4, *(dos_ptr + i));
+
+    putchar(10);
+    ptr2vector = dos_vector;
+    for(size_t i = 0; i < 3; i++) {
+        for(size_t j = 0; j < 4; j++)
+            printf("%2d ", *(ptr2vector[i] + j));
+        
+        putchar(10);
+    }
+
+    return 0;
+}