From b60f26f0903a8a2da6939b7d9abe18b131ffd4a3 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 24 Apr 2025 15:34:39 +0200 Subject: [PATCH] 25.4.5 --- text.txt | 1 + wortlen.c | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 text.txt diff --git a/text.txt b/text.txt new file mode 100644 index 0000000..c7a0654 --- /dev/null +++ b/text.txt @@ -0,0 +1 @@ +Hallo ich bin eine Testfile. \ No newline at end of file diff --git a/wortlen.c b/wortlen.c index d210d3a..9c63c85 100644 --- a/wortlen.c +++ b/wortlen.c @@ -1,7 +1,33 @@ #include -int main() -{ +#define MAX_LEN 100 + +int main() { + char c; + int ausgabe_laengen[MAX_LEN] = {0}; + int laenge = 0; + + //printf("A:%d, Z:%d, a:%d, z:%d\n", 'A', 'Z', 'a', 'z'); + + c = getchar(); + + do { + if(c >= 65 && c <= 90 || c >= 97 && c <= 122){ + laenge++; + } else if(laenge > 0){ + ausgabe_laengen[laenge]++; + laenge = 0; + } + }while((c = getchar())!= EOF); + printf("Wortlaenge |\tAnzahl |\n"); printf("-----------+-----------|\n"); + + for (int i = 1; i < MAX_LEN; ++i) { + if(ausgabe_laengen[i] != 0){ + printf("%10d |%10d |\n",i, ausgabe_laengen[i]); + } + } + + return 0; } \ No newline at end of file