Nimbin[12]?C-Tutorial / tutorium_pe1_se1 / commits / 3117304

tutorium_pe1_se1 git · main

self-explaining C files

c tutorial · first commit 2025-11-15 · last commit 2025-11-30 (11 months ago) · synced 1 hour ago · upstream: git.ide3.de/hsnr/tutorium_pe1_se1

C 100%
git clone https://git.christianimmanuel.de/c-tutorial/tutorium_pe1_se1.gitwget https://git.christianimmanuel.de/c-tutorial/tutorium_pe1_se1/archive/tutorium_pe1_se1.tar.gz

Add example

Christian Immanuel · 2025-11-23 11:03 · 311730447a0420145b3f454e765994bce3ed5104

 13_enum.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 49 insertions(+), 3 deletions(-)

diff --git a/13_enum.c b/13_enum.c
index 80b441e..30a10bd 100644
--- a/13_enum.c
+++ b/13_enum.c
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <string.h>
 
 enum ThatsJustDumn {
     NUMBER_0, // NUMBER_0 wird durch die konstante Zahl 0 ersetzt
@@ -43,9 +44,14 @@ enum Days { // wir deklarieren hier einen datentyp "enum Days"
                // da man somit das letzte element des enums eralten kann!
 };
 
-void print_WochentagFromEnum(enum Days d);
 
-int main() {
+
+void 
+print_WochentagFromEnum(enum Days d);
+
+
+int
+main() {
 
     printf("Ist NUMBER_0 == 0 ?\n\tAntwort ist: %d\n", NUMBER_0 == 0);
     printf("Ist NUMBER_2 == 2 ?\n\tAntwort ist: %d\n", NUMBER_2 == 2);
@@ -76,9 +82,49 @@ int main() {
     wochentag = MITTWOCH;
     printf("Wochentag auf MITTWOCH gesetzt: ");
     print_WochentagFromEnum(wochentag);
+
+
+
+    // Anderes Beispiel
+    enum Messages_e {
+        MESSAGE_SUCCESS,
+        MESSAGE_ARRAY_OUT_OF_BOUNDS,
+        MESSAGE_PROGRAM_END
+    };
+
+    char messages[3][150];
+    strcpy(messages[MESSAGE_SUCCESS],             "Array access succeeded!\n");
+    strcpy(messages[MESSAGE_ARRAY_OUT_OF_BOUNDS], "Array access is out of bounds!\n");
+    strcpy(messages[MESSAGE_PROGRAM_END],         "Program finished!\n");
+
+
+#define ARR_SIZE 5
+    int arr[ARR_SIZE] = {11, 12, 13, 14, 15};
+
+    int arr_index;
+    printf("Bitte gib eine index zahl des arrays ein[0-%d]: ", ARR_SIZE-1);
+    scanf("%d", &arr_index);
+
+    if (arr_index > ARR_SIZE || arr_index < 0)
+        fprintf(stderr, "%s\n", messages[MESSAGE_ARRAY_OUT_OF_BOUNDS]); // mit fprintf können wir an einen bestimmten ort eine nachricht schreiben (file printf)
+                                                                        //  ich schreibe an stderr, was die error ausgabe des programms ist..
+    else {
+        printf("%s\n", messages[MESSAGE_SUCCESS]);
+        printf("Array at index %d is: %d\n", arr_index, arr[arr_index]);
+    }
+
+
+    printf("%s\n", messages[MESSAGE_PROGRAM_END]);
+
+
+    return 0;
 }
 
-void print_WochentagFromEnum(enum Days d) {
+
+
+
+void
+print_WochentagFromEnum(enum Days d) {
     switch (d) { // da wochentag eine Ganzzahl ist können wir einen switch case verwenden!
         case MONTAG:
             printf("Montag");