now really final ass2
authorMart Lubbers <mart@martlubbers.net>
Mon, 9 Feb 2015 12:01:28 +0000 (13:01 +0100)
committerMart Lubbers <mart@martlubbers.net>
Mon, 9 Feb 2015 12:01:28 +0000 (13:01 +0100)
ass2/mart/sws1-s4109503-s4202015/exercise1b [new file with mode: 0755]
ass2/mart/sws1-s4109503-s4202015/exercise1b.c
ass2/mart/sws1-s4109503-s4202015/exercise1d [new file with mode: 0755]
ass2/mart/sws1-s4109503-s4202015/exercise1d.c
ass2/mart/sws1-s4109503-s4202015/exercise2 [new file with mode: 0755]
ass2/mart/sws1-s4109503-s4202015/exercise2.c
ass2/mart/sws1-s4109503-s4202015/exercise3 [new file with mode: 0755]
ass2/mart/sws1-s4109503-s4202015/exercise3.c

diff --git a/ass2/mart/sws1-s4109503-s4202015/exercise1b b/ass2/mart/sws1-s4109503-s4202015/exercise1b
new file mode 100755 (executable)
index 0000000..6999b5e
Binary files /dev/null and b/ass2/mart/sws1-s4109503-s4202015/exercise1b differ
diff --git a/ass2/mart/sws1-s4109503-s4202015/exercise1d b/ass2/mart/sws1-s4109503-s4202015/exercise1d
new file mode 100755 (executable)
index 0000000..1b7b59b
Binary files /dev/null and b/ass2/mart/sws1-s4109503-s4202015/exercise1d differ
index 9e629ee..3200729 100644 (file)
@@ -1,6 +1,5 @@
 #include <stdint.h>
 #include <stdio.h>
-#include <stdlib.h>
 
 int main(void)
 {
diff --git a/ass2/mart/sws1-s4109503-s4202015/exercise2 b/ass2/mart/sws1-s4109503-s4202015/exercise2
new file mode 100755 (executable)
index 0000000..8760b2c
Binary files /dev/null and b/ass2/mart/sws1-s4109503-s4202015/exercise2 differ
index 45a50d6..dd4a236 100644 (file)
@@ -1,12 +1,10 @@
 #include <stdio.h>
-#include <stdlib.h>
+#include <stdint.h> /* Because typing unsigned char takes too much characters*/
 
-void print(char *address, unsigned int size)
+void pm(uint8_t *a, size_t s)
 {
-       for(unsigned char i = 0; i < size; i++) {
-               unsigned char value = (unsigned char)*(address + i);
-               printf("%p  0x%02X           %3u\n", address + i, value, value);
-       }
+       for(uint8_t i = 0; i < s; i++)
+               printf("%p\t0x%02X\t\t%3u\n", a + i, *(a + i), *(a + i));
 }
 
 int main(void)
@@ -16,12 +14,12 @@ int main(void)
        long sn1 = 4109503;
        long sn2 = 4202015;
        int y[2] = {0x11223344, 0x44332211};
-       printf("address         content (hex)  content(dec)\n");
-       printf("------------------------------------------\n");
-       print((char *)&i, sizeof(i));
-       print((char *)&x, sizeof(x));
-       print((char *)&sn1, sizeof(sn1));
-       print((char *)&sn2, sizeof(sn2));
-       print((char *)&y, 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));
        return 0;
 }
diff --git a/ass2/mart/sws1-s4109503-s4202015/exercise3 b/ass2/mart/sws1-s4109503-s4202015/exercise3
new file mode 100755 (executable)
index 0000000..d0c9e59
Binary files /dev/null and b/ass2/mart/sws1-s4109503-s4202015/exercise3 differ
index f740e04..96c770f 100644 (file)
@@ -3,7 +3,7 @@
 #include <stdbool.h>
 
 int main(void){
-       printf("A bool uses %lu bytes\n", sizeof(bool));
+       printf("A bool uses %zu bytes\n", sizeof(bool));
        printf("Hex representation of true: %X\n", true);
        printf("Hex representation of false: %X\n", false);
 /* Running the following code shows that all but the 0x00 byte evaluate true */