update
authorMart Lubbers <mart@martlubbers.net>
Thu, 12 Feb 2015 08:04:28 +0000 (09:04 +0100)
committerMart Lubbers <mart@martlubbers.net>
Thu, 12 Feb 2015 08:04:28 +0000 (09:04 +0100)
ass2/mart/sws1-s4109503-s4202015/exercise1e.txt
ass2/mart/sws1-s4109503-s4202015/exercise2.c

index 6c4b271..88207e0 100644 (file)
@@ -1 +1 @@
-{ for ((i=0;i<10;i++)); do ./exercise1d | wc -l; done; } > exercise1d.txt
+{ for $(seq 0 9); do ./exercise1d | wc -l; done; } > exercise1d.txt
index 1473e4d..239b7a6 100644 (file)
@@ -1,10 +1,9 @@
 #include <stdio.h>
-#include <stdint.h> /* Because typing unsigned char takes too much characters*/
 
-void pm(uint8_t *a, size_t s)
+void pm(unsigned char *a, size_t s)
 {
-       for(size_t i = 0; i < s; i++)
-               printf("%p\t0x%02X\t\t%3u\n", a + i, *(a + i), *(a + i));
+       for(unsigned char *i = a; i < a+s; i++)
+               printf("%p\t0x%02X\t\t%3u\n", i, *i, *i);
 }
 
 int main(void)
@@ -14,12 +13,17 @@ int main(void)
        long sn1 = 4109503;
        long sn2 = 4202015;
        int y[2] = {0x11223344, 0x44332211};
+       printf("short i  = %zu byte(s)\n", sizeof(i));
+       printf("char x   = %zu byte(s)\n", sizeof(x));
+       printf("long sn1 = %zu byte(s)\n", sizeof(sn1));
+       printf("long sn2 = %zu byte(s)\n", sizeof(sn2));
+       printf("int[2] y = %zu byte(s)\n\n", sizeof(y));
        printf("address\t\tcontent (hex)\tcontent(dec)\n");
-       printf("-------------------------------------------\n");
-       pm((uint8_t *)&i, sizeof(i));
-       pm((uint8_t *)&x, sizeof(x));
-       pm((uint8_t *)&sn1, sizeof(sn1));
-       pm((uint8_t *)&sn2, sizeof(sn2));
-       pm((uint8_t *)&y, sizeof(y));
+       printf("--------------------------------------------\n");
+       pm((unsigned char *)&i, sizeof(i));
+       pm((unsigned char *)&x, 1);
+       pm((unsigned char *)&sn1, sizeof(sn1));
+       pm((unsigned char *)&sn2, sizeof(sn2));
+       pm((unsigned char *)&y, sizeof(y));
        return 0;
 }