diff --git a/.idea/Info2P5.iml b/.idea/Info2P5.iml deleted file mode 100644 index 4c94235..0000000 --- a/.idea/Info2P5.iml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/a.exe b/a.exe index c2f8b01..6ddd8c9 100644 Binary files a/a.exe and b/a.exe differ diff --git a/strilist.c b/strilist.c new file mode 100644 index 0000000..e6cef4e --- /dev/null +++ b/strilist.c @@ -0,0 +1,55 @@ +#include +#include +#include + +#define NUM_DIGITS 10 + +int main(void) { + char *strichlisten[NUM_DIGITS] = {NULL}; + int counts[NUM_DIGITS] = {0}; + int c; + + // Initialisiere alle Strichlisten als leere Strings + for (int i = 0; i < NUM_DIGITS; ++i) { + strichlisten[i] = malloc(1); + if (!strichlisten[i]) { + fprintf(stderr, "Speicherfehler!\n"); + // Speicher aufräumen + for (int j = 0; j < i; ++j) free(strichlisten[j]); + return 1; + } + strichlisten[i][0] = '\0'; + } + + // Einlesen der Ziffern + while ((c = getchar()) != EOF) { + if (c >= '0' && c <= '9') { + int idx = c - '0'; + counts[idx]++; + + // Länge des alten Strings + size_t oldlen = strlen(strichlisten[idx]); + // Speicher für neuen String (+1 für neuen Strich, +1 für '\0') + char *neu = malloc(oldlen + 2); + if (!neu) { + fprintf(stderr, "Speicherfehler!\n"); + // Speicher aufräumen + for (int j = 0; j < NUM_DIGITS; ++j) free(strichlisten[j]); + return 1; + } + strcpy(neu, strichlisten[idx]); + neu[oldlen] = '|'; + neu[oldlen+1] = '\0'; + free(strichlisten[idx]); + strichlisten[idx] = neu; + } + } + + // Ausgabe + for (int i = 0; i < NUM_DIGITS; ++i) { + printf("%d: %d %s\n", i, counts[i], strichlisten[i]); + free(strichlisten[i]); + } + + return 0; +} \ No newline at end of file diff --git a/wochentag.exe b/wochentag.exe index 422700b..2f71978 100644 Binary files a/wochentag.exe and b/wochentag.exe differ diff --git a/wortlen.exe b/wortlen.exe index fd3278f..4c20d69 100644 Binary files a/wortlen.exe and b/wortlen.exe differ