From: Mart Lubbers Date: Mon, 9 Feb 2015 12:01:28 +0000 (+0100) Subject: now really final ass2 X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=4a310e02745823dd7a6e84fd81225b2cf1563289;p=sws1-1415.git now really final ass2 --- diff --git a/ass2/mart/sws1-s4109503-s4202015/exercise1b b/ass2/mart/sws1-s4109503-s4202015/exercise1b new file mode 100755 index 0000000..6999b5e Binary files /dev/null and b/ass2/mart/sws1-s4109503-s4202015/exercise1b differ diff --git a/ass2/mart/sws1-s4109503-s4202015/exercise1b.c b/ass2/mart/sws1-s4109503-s4202015/exercise1b.c index c9c0f52..c9473bd 100644 --- a/ass2/mart/sws1-s4109503-s4202015/exercise1b.c +++ b/ass2/mart/sws1-s4109503-s4202015/exercise1b.c @@ -1,5 +1,4 @@ #include -#include int main(void) { diff --git a/ass2/mart/sws1-s4109503-s4202015/exercise1d b/ass2/mart/sws1-s4109503-s4202015/exercise1d new file mode 100755 index 0000000..1b7b59b Binary files /dev/null and b/ass2/mart/sws1-s4109503-s4202015/exercise1d differ diff --git a/ass2/mart/sws1-s4109503-s4202015/exercise1d.c b/ass2/mart/sws1-s4109503-s4202015/exercise1d.c index 9e629ee..3200729 100644 --- a/ass2/mart/sws1-s4109503-s4202015/exercise1d.c +++ b/ass2/mart/sws1-s4109503-s4202015/exercise1d.c @@ -1,6 +1,5 @@ #include #include -#include int main(void) { diff --git a/ass2/mart/sws1-s4109503-s4202015/exercise2 b/ass2/mart/sws1-s4109503-s4202015/exercise2 new file mode 100755 index 0000000..8760b2c Binary files /dev/null and b/ass2/mart/sws1-s4109503-s4202015/exercise2 differ diff --git a/ass2/mart/sws1-s4109503-s4202015/exercise2.c b/ass2/mart/sws1-s4109503-s4202015/exercise2.c index 45a50d6..dd4a236 100644 --- a/ass2/mart/sws1-s4109503-s4202015/exercise2.c +++ b/ass2/mart/sws1-s4109503-s4202015/exercise2.c @@ -1,12 +1,10 @@ #include -#include +#include /* 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 index 0000000..d0c9e59 Binary files /dev/null and b/ass2/mart/sws1-s4109503-s4202015/exercise3 differ diff --git a/ass2/mart/sws1-s4109503-s4202015/exercise3.c b/ass2/mart/sws1-s4109503-s4202015/exercise3.c index f740e04..96c770f 100644 --- a/ass2/mart/sws1-s4109503-s4202015/exercise3.c +++ b/ass2/mart/sws1-s4109503-s4202015/exercise3.c @@ -3,7 +3,7 @@ #include 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 */