diff --git a/20201119/chars-1.c b/20201119/chars-1.c new file mode 100644 index 0000000000000000000000000000000000000000..7089769e0a9e70cfff426c4d0fa15c89b562cec0 --- /dev/null +++ b/20201119/chars-1.c @@ -0,0 +1,8 @@ +#include <stdio.h> + +int main (void) +{ + printf ("%d\n", '*'); + printf ("%c\n", 71); + return 0; +} diff --git a/20201119/chars-2.c b/20201119/chars-2.c new file mode 100644 index 0000000000000000000000000000000000000000..326aa6334808f996101cea23435e8aa4d71940c3 --- /dev/null +++ b/20201119/chars-2.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + printf ("%d\n", '*'); + printf ("%x\n", '*'); + printf ("%c\n", 71); + return 0; +} diff --git a/20201119/chars-3.c b/20201119/chars-3.c new file mode 100644 index 0000000000000000000000000000000000000000..515341ce8681ea1596761494b53c431f698a9d5d --- /dev/null +++ b/20201119/chars-3.c @@ -0,0 +1,10 @@ +#include <stdio.h> + +int main (void) +{ + printf ("%d\n", '*'); + printf ("%x\n", '*'); + printf ("%c\n", 71); + printf ("%c\n", 0x65); + return 0; +} diff --git a/20201119/strings-1.c b/20201119/strings-1.c new file mode 100644 index 0000000000000000000000000000000000000000..81bc3cda8affb6268786ac989dd2907d9a84783a --- /dev/null +++ b/20201119/strings-1.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + char hello[] = "Hello, world!\n"; + for (char *p = hello; *p; p++) + printf ("%d", *p); + return 0; +} diff --git a/20201119/strings-10.c b/20201119/strings-10.c new file mode 100644 index 0000000000000000000000000000000000000000..f01f72c7803ae94d6f35f99f8777b10a0e43f5e0 --- /dev/null +++ b/20201119/strings-10.c @@ -0,0 +1,8 @@ +#include <stdio.h> + +int main (void) +{ + char hello[] = { 'H', 'a', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\n', 0 }; + printf ("%s", hello); + return 0; +} diff --git a/20201119/strings-11.c b/20201119/strings-11.c new file mode 100644 index 0000000000000000000000000000000000000000..ced6e34e6d60e600655c4152028416be1139c583 --- /dev/null +++ b/20201119/strings-11.c @@ -0,0 +1,12 @@ +#include <stdio.h> + +int main (void) +{ + char hello[] = { 'H', 'a', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '\n' }; + /* Hier fehlt das Null-Symbol am Ende des Strings! + ==> printf() liest über das String-Ende hinaus, + bis es im Speicher zufällig auf eine 0 stößt. + Dies kann zu einem Absturz führen! */ + printf ("%s", hello); + return 0; +} diff --git a/20201119/strings-12.c b/20201119/strings-12.c new file mode 100644 index 0000000000000000000000000000000000000000..b35da3453417c6087ce1a3b0db0f10d7e5070231 --- /dev/null +++ b/20201119/strings-12.c @@ -0,0 +1,8 @@ +#include <stdio.h> + +int main (void) +{ + char *hello = "Hello, world!"; + printf ("%s\n", hello); + return 0; +} diff --git a/20201119/strings-13.c b/20201119/strings-13.c new file mode 100644 index 0000000000000000000000000000000000000000..0165d83890b6d0bd202dec2eb62bde98f838db3f --- /dev/null +++ b/20201119/strings-13.c @@ -0,0 +1,7 @@ +#include <stdio.h> + +int main (void) +{ + printf ("%s\n", "Hallo, Welt!"); + return 0; +} diff --git a/20201119/strings-14.c b/20201119/strings-14.c new file mode 100644 index 0000000000000000000000000000000000000000..32e64d466014a6c8244f3297198876f1a4a48d5a --- /dev/null +++ b/20201119/strings-14.c @@ -0,0 +1,7 @@ +#include <stdio.h> + +int main (void) +{ + printf ("%s\n", "Hallo, Welt!" + 4); + return 0; +} diff --git a/20201119/strings-15.c b/20201119/strings-15.c new file mode 100644 index 0000000000000000000000000000000000000000..2615531f95f77c4d5f1577eff9f8c8180a3b30ab --- /dev/null +++ b/20201119/strings-15.c @@ -0,0 +1,7 @@ +#include <stdio.h> + +int main (void) +{ + printf ("Die Ersparnis beträgt %d%%.\n", 42); + return 0; +} diff --git a/20201119/strings-16.c b/20201119/strings-16.c new file mode 100644 index 0000000000000000000000000000000000000000..43b27266c61a8d05e62a9e5cd5881447d5300ccc --- /dev/null +++ b/20201119/strings-16.c @@ -0,0 +1,7 @@ +#include <stdio.h> + +int main (void) +{ + printf ("Die Ersparnis beträgt %d%c.\n", 42, '%'); + return 0; +} diff --git a/20201119/strings-17.c b/20201119/strings-17.c new file mode 100644 index 0000000000000000000000000000000000000000..3f8e223099e7183a4ecb743458ae1baaed7fdead --- /dev/null +++ b/20201119/strings-17.c @@ -0,0 +1,7 @@ +#include <stdio.h> + +int main (void) +{ + printf ("Der Format-String lautet: %s\n", "%02hhx"); + return 0; +} diff --git a/20201119/strings-18.c b/20201119/strings-18.c new file mode 100644 index 0000000000000000000000000000000000000000..ac0ad7c70f69972cde6062738962a3b380ab1d7b --- /dev/null +++ b/20201119/strings-18.c @@ -0,0 +1,7 @@ +#include <stdio.h> + +int main (void) +{ + printf ("Добрый день!\n"); + return 0; +} diff --git a/20201119/strings-19.c b/20201119/strings-19.c new file mode 100644 index 0000000000000000000000000000000000000000..7f91d53741d7a56e165839108d0c25dc4701ac8f --- /dev/null +++ b/20201119/strings-19.c @@ -0,0 +1,7 @@ +#include <stdio.h> + +int main (void) +{ + printf ("%s\n", "Добрый день!"); + return 0; +} diff --git a/20201119/strings-2.c b/20201119/strings-2.c new file mode 100644 index 0000000000000000000000000000000000000000..4df32974a15ef2752512cc8b9889381b5a0917cd --- /dev/null +++ b/20201119/strings-2.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + char hello[] = "Hello, world!\n"; + for (char *p = hello; *p; p++) + printf ("%c", *p); + return 0; +} diff --git a/20201119/strings-20.c b/20201119/strings-20.c new file mode 100644 index 0000000000000000000000000000000000000000..17d6d120cdbee211a3316b0a2ff0f5f0e93fb7b6 --- /dev/null +++ b/20201119/strings-20.c @@ -0,0 +1,7 @@ +#include <stdio.h> + +int main (void) +{ + printf ("%d\n", "Д"); /* Falsch: gibt die Speicheradresse des "Д" aus. */ + return 0; +} diff --git a/20201119/strings-21.c b/20201119/strings-21.c new file mode 100644 index 0000000000000000000000000000000000000000..ba95961c605d7b1375f76ddca48b14442892f465 --- /dev/null +++ b/20201119/strings-21.c @@ -0,0 +1,7 @@ +#include <stdio.h> + +int main (void) +{ + printf ("%d\n", 'Д'); /* Der ausgegebene Zahlenwert ist _nicht_ der Unicode für 'Д'. */ + return 0; +} diff --git a/20201119/strings-22.c b/20201119/strings-22.c new file mode 100644 index 0000000000000000000000000000000000000000..982de510faa8dcbd2bcdf285d007b3ccdb98846b --- /dev/null +++ b/20201119/strings-22.c @@ -0,0 +1,7 @@ +#include <stdio.h> + +int main (void) +{ + printf ("%08x\n", 'Д'); /* Der ausgegebene Zahlenwert ist _nicht_ der Unicode für 'Д'. */ + return 0; /* Für korrekte Handhabung von UTF-8: Bibliothek verwenden. */ +} diff --git a/20201119/strings-23.c b/20201119/strings-23.c new file mode 100644 index 0000000000000000000000000000000000000000..4b89550c9e9572581894704b4e541346232bb569 --- /dev/null +++ b/20201119/strings-23.c @@ -0,0 +1,8 @@ +#include <stdio.h> + +int main (void) +{ + printf ("%08x\n", 'ä'); /* Der ausgegebene Zahlenwert ist _nicht_ der Unicode für 'ä', */ + return 0; /* sondern die UTF-8-Kodierung für 'ä'. */ + /* Für korrekte Handhabung von UTF-8: Bibliothek verwenden. */ +} diff --git a/20201119/strings-3.c b/20201119/strings-3.c new file mode 100644 index 0000000000000000000000000000000000000000..5c36db92dac8129b66d1f0ff6b709534b9e1bdb3 --- /dev/null +++ b/20201119/strings-3.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + char hello[] = { 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33, 10, 0 }; + for (char *p = hello; *p; p++) + printf ("%c", *p); + return 0; +} diff --git a/20201119/strings-4.c b/20201119/strings-4.c new file mode 100644 index 0000000000000000000000000000000000000000..aa189d9f4170e47899e9e7854070af0f73573517 --- /dev/null +++ b/20201119/strings-4.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + char hello[] = { 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33, 10, 0 }; + for (char *p = hello; !*p; p++) + printf ("%c", *p); + return 0; +} diff --git a/20201119/strings-5.c b/20201119/strings-5.c new file mode 100644 index 0000000000000000000000000000000000000000..f37edf15be04770135c5b178d204638c18f7f12b --- /dev/null +++ b/20201119/strings-5.c @@ -0,0 +1,10 @@ +#include <stdio.h> + +int main (void) +{ + char hello[] = "Hällou, wörldt!\n"; + for (char *p = hello; *p; p++) + printf ("%x ", *p); + printf ("\n"); + return 0; +} diff --git a/20201119/strings-6.c b/20201119/strings-6.c new file mode 100644 index 0000000000000000000000000000000000000000..3ae70e168f0a7101ffecb34e407a919dd7c19cf0 --- /dev/null +++ b/20201119/strings-6.c @@ -0,0 +1,10 @@ +#include <stdio.h> + +int main (void) +{ + char hello[] = "Hällou, wörldt!\n"; + for (char *p = hello; *p; p++) + printf ("%hhx ", *p); + printf ("\n"); + return 0; +} diff --git a/20201119/strings-7.c b/20201119/strings-7.c new file mode 100644 index 0000000000000000000000000000000000000000..49dfb3e2a213c46448c33ba949af5ab281018677 --- /dev/null +++ b/20201119/strings-7.c @@ -0,0 +1,10 @@ +#include <stdio.h> + +int main (void) +{ + char hello[] = "Hällou, wörldt!\n"; + for (char *p = hello; *p; p++) + printf ("%02hhx ", *p); + printf ("\n"); + return 0; +} diff --git a/20201119/strings-8.c b/20201119/strings-8.c new file mode 100644 index 0000000000000000000000000000000000000000..2f739c8c80d6923e9f17a184a629a37877f6131c --- /dev/null +++ b/20201119/strings-8.c @@ -0,0 +1,8 @@ +#include <stdio.h> + +int main (void) +{ + char hello[] = "Hallo, Welt!\n"; + printf ("%s", hello); + return 0; +} diff --git a/20201119/strings-9.c b/20201119/strings-9.c new file mode 100644 index 0000000000000000000000000000000000000000..74f11c34440c4ed87b886ef9aad8c9a39cb70a33 --- /dev/null +++ b/20201119/strings-9.c @@ -0,0 +1,8 @@ +#include <stdio.h> + +int main (void) +{ + char hello[] = { 72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33, 10, 0 }; + printf ("%s", hello); + return 0; +}