From 7560cc4942f39553de76072a963e56c6ab8d38f9 Mon Sep 17 00:00:00 2001
From: Peter Gerwinski <peter.gerwinski@hs-bochum.de>
Date: Thu, 19 Nov 2020 17:29:30 +0100
Subject: [PATCH] weitere Beispiele 17.11.2020

---
 20201119/chars-1.c    |  8 ++++++++
 20201119/chars-2.c    |  9 +++++++++
 20201119/chars-3.c    | 10 ++++++++++
 20201119/strings-1.c  |  9 +++++++++
 20201119/strings-10.c |  8 ++++++++
 20201119/strings-11.c | 12 ++++++++++++
 20201119/strings-12.c |  8 ++++++++
 20201119/strings-13.c |  7 +++++++
 20201119/strings-14.c |  7 +++++++
 20201119/strings-15.c |  7 +++++++
 20201119/strings-16.c |  7 +++++++
 20201119/strings-17.c |  7 +++++++
 20201119/strings-18.c |  7 +++++++
 20201119/strings-19.c |  7 +++++++
 20201119/strings-2.c  |  9 +++++++++
 20201119/strings-20.c |  7 +++++++
 20201119/strings-21.c |  7 +++++++
 20201119/strings-22.c |  7 +++++++
 20201119/strings-23.c |  8 ++++++++
 20201119/strings-3.c  |  9 +++++++++
 20201119/strings-4.c  |  9 +++++++++
 20201119/strings-5.c  | 10 ++++++++++
 20201119/strings-6.c  | 10 ++++++++++
 20201119/strings-7.c  | 10 ++++++++++
 20201119/strings-8.c  |  8 ++++++++
 20201119/strings-9.c  |  8 ++++++++
 26 files changed, 215 insertions(+)
 create mode 100644 20201119/chars-1.c
 create mode 100644 20201119/chars-2.c
 create mode 100644 20201119/chars-3.c
 create mode 100644 20201119/strings-1.c
 create mode 100644 20201119/strings-10.c
 create mode 100644 20201119/strings-11.c
 create mode 100644 20201119/strings-12.c
 create mode 100644 20201119/strings-13.c
 create mode 100644 20201119/strings-14.c
 create mode 100644 20201119/strings-15.c
 create mode 100644 20201119/strings-16.c
 create mode 100644 20201119/strings-17.c
 create mode 100644 20201119/strings-18.c
 create mode 100644 20201119/strings-19.c
 create mode 100644 20201119/strings-2.c
 create mode 100644 20201119/strings-20.c
 create mode 100644 20201119/strings-21.c
 create mode 100644 20201119/strings-22.c
 create mode 100644 20201119/strings-23.c
 create mode 100644 20201119/strings-3.c
 create mode 100644 20201119/strings-4.c
 create mode 100644 20201119/strings-5.c
 create mode 100644 20201119/strings-6.c
 create mode 100644 20201119/strings-7.c
 create mode 100644 20201119/strings-8.c
 create mode 100644 20201119/strings-9.c

diff --git a/20201119/chars-1.c b/20201119/chars-1.c
new file mode 100644
index 0000000..7089769
--- /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 0000000..326aa63
--- /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 0000000..515341c
--- /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 0000000..81bc3cd
--- /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 0000000..f01f72c
--- /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 0000000..ced6e34
--- /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 0000000..b35da34
--- /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 0000000..0165d83
--- /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 0000000..32e64d4
--- /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 0000000..2615531
--- /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 0000000..43b2726
--- /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 0000000..3f8e223
--- /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 0000000..ac0ad7c
--- /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 0000000..7f91d53
--- /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 0000000..4df3297
--- /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 0000000..17d6d12
--- /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 0000000..ba95961
--- /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 0000000..982de51
--- /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 0000000..4b89550
--- /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 0000000..5c36db9
--- /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 0000000..aa189d9
--- /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 0000000..f37edf1
--- /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 0000000..3ae70e1
--- /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 0000000..49dfb3e
--- /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 0000000..2f739c8
--- /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 0000000..74f11c3
--- /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;
+}
-- 
GitLab